-1

I have a simple question, but I cant find the way to do it. I need to redirect or rewrite this:

http://mydomain.com/libro.php?isbn=9788493652470 

To this:

http://mydomain.com/busqueda.php?busqueda=medimecum

I have already tried this but it doesn’t work:

Redirect 301 /libro.php?isbn=9788493652470 http://mydomain.com/busqueda.php?busqueda=medimecum
Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
  • 1
    possible duplicate of [How to make a redirect in PHP?](http://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php) – Giacomo1968 Jun 18 '14 at 16:01
  • Those two files share the whole head part, and I tried also the PHP solution "header()", but it goes on a loop... I cant make it work, even using the "if ($_GET=9788493652470)" – user3753292 Jun 18 '14 at 16:08
  • You can't match query string in `Redirect` directive use `mod_rewrite` rules instead. – anubhava Jun 18 '14 at 16:12
  • @anubhava Exactly. Posted an answer with a `RewriteCond` for a query string. Works well in my tests. – Giacomo1968 Jun 18 '14 at 19:48

1 Answers1

1

A straight Redirect would not work well. But using mod_rewrite with a RewriteCond for a query string would work well. This should work for your example:

RewriteEngine On
RewriteCond %{QUERY_STRING} isbn=9788493652470
RewriteRule ^libro.php http://mydomain.com/busqueda.php?busqueda=medimecum [L,R=301]

Now looking at your question again it’s not clear if you want to pass along the original query string, correct? So this URL:

http://mydomain.com/libro.php?isbn=9788493652470

Would become this URL:

http://mydomain.com/busqueda.php?busqueda=medimecum&isbn=9788493652470

But if somehow you wanted to do that, you could add the QSA (Query String Append) flag to that RewriteRule like this:

RewriteEngine On
RewriteCond %{QUERY_STRING} isbn=9788493652470
RewriteRule ^libro\.php http://mydomain.com/busqueda.php?busqueda=medimecum [L,R=301,QSA]
Giacomo1968
  • 25,759
  • 11
  • 71
  • 103