Today I ran into an issue which I could not figure out for quite a while. I was trying to redirect a url to another url using RewriteRule. It was supposed to be a pretty straightforward redirect which made it even more annoying than complicated ones. Hopefully somebody is able to explain what I am missing here and if my solution is a good solution or not.
I needed to redirect a url:Â http://www.example.com/testpage.php?foo=bar to http://www.example.com/
So I added this to .htaccess file:
RewriteRule ^testpage\.php / [R=301,L]
This did do a 301 redirect as I wanted but query string passed so my redirected url looked like:Â http://www.example.com/?foo=bar
Obviously this is not what I wanted so in order for me to fix it, I had to take a rather lame approach. My new redirect is:
RewriteRule ^testpage\.php /?
[R=301,L]
The …
[Read more]