I'm trying to set a simple htaccess rule, but is not working.
I think the problem is with the ?
and =
characters?
The code is:
Options +FollowSymLinks
ErrorDocument 404 /php/404redirect.php
RewriteEngine on
RewriteRule ^productos.php?id=([0-9]+)$ /?view=productos&id=$1 [L,NE,B,QSA]
This always give me error 404.
What I want is redirect all requests from:www.example.com/productos.php?id=X
towww.example.com/?view=productos&id=X
Querystring is not part of match in RewriteRule directive, to redirect query strings, you need to use RewriteCond one of the following options :
option 1
RewriteEngine on
RewriteCond %{THE_REQUEST} /product\.php\?id=([^&\s] [NC]
RewriteRule ^ /?view-product&id=%1? [NC,L,R]
option 2
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=([^&]+)$ [NC]
RewriteRule ^product\.php$ /?view-product&id=%1? [NC,L,R]
We use an empty question mark ? at the end of the target url to discard the old query strings, otherwise these query strings get appened to the target url by default.
Change the R to R=301 if you want to make the redirection permanent.
RewriteRule ^productos.php /?view=productos [L,NE,B,QSA]
or if you want to redirect
RewriteRule ^productos.php /?view=productos [L,NE,B,QSA,R=301]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With