Forum Moderators: phranque
example.com/index.php?tag=foo
example.com/tag/foo
I am in the process of trying to get .htaccess to redirect from the query string to the directory, and so far this is what I've got:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^tag=(.*)$
RewriteRule .* /tag/%1 [R=301,L]
This does nothing. I also tried:
RewriteRule ^index\.php$ /tag/%1 [R=301,L]
but got no results. Any advice on where I've gone astray would be greatly appreciated.
However, despite the fact that "I get nothing" provides us with no information, I'd guess that mod_rewrite is not enabled on your server. Have you tried a dirt-simple mod_rewrite function, such as
RewriteRule ^foo\.html$ http://www.google.com [R=301,L]
If that doesn't work and does not create a meaningful entry in your server error log, then it's likely you don't have mod_rewrite installed or enabled.
Also make sure you are completely flushing your browser cache after any change to your .htaccess code or server configuration. If the URLs you use to test have been previously cached by your browser, then your test requests will be served from your browser cache, no requests will be sent to your server, and therefore, no server-side code can/will have any effect on the results.
Jim
jdMorgan, thanks for the idea to test a really simple rule, if I hadn't been tooling around with that I never would have figured it out.
also, in case anyone is looking at this for future reference, make sure your rule is actually
RewriteRule .* /tag/%1/? [R=301,L]
without the trailing? the query string will be re-appended and it will rewrite itself infinitely.