and what rewrite rules have you tried?
I’m definitely no expert, but initially I tried
RewriteCond %{QUERY_STRING} ^tag=$1
RewriteRule ^/index.php$1 ^/tag/$1 [R=301,L]
This to me seems like the most simplistic solution, everything beyond that was just tinkering (removing the ^, changing $1 to just $, etc)
RewriteRule ^tag/(.+)/?$ /index.php?tag=$1 [QSA,L]
try that. thats untested.
actually oops:
RewriteRule ^tag/([^/]*)/?$ /index.php?tag=$1 [QSA,L]
and Ill admit I dont know what you mean by “reads the query_string as opposed to writing each one out.“
that kinda confused me, so the above might not be what youre after.
meaning I know what the query string is, but Im not understanding if youre just trying to prettify those, or something else.
Basically there are 2 URLs that are generated by WordPress when you tag a post.
example.com/index.php?tag=example
and
example.com/tag/example/
So I want to consolidate those by redirecting all index.php?tag=example pages to its corresponding /tag/example/ directory.
I would have thought that if you have the pretty permalinks turned on, WordPress 2.3 will do that by itself, as part of the canonical permalinks stuff. Apparently not.
Might want to submit a bug report about this one on trac.
Also:
RewriteCond %{QUERY_STRING} ^tag=(.*)$
RewriteRule .* /tag/%1 [R,L]
Patterns in RewriteRules don’t match query-strings. You have to match them in RewriteCond’s and use their values in back references later (with % marks instead of $ marks).
I must still be missing something here. I tried:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^tag=(.*)$
RewriteRule .* /tag/%1 [R,L]
But I still don’t get anything redirecting. Do you think it’s related to the RewriteBase? I am pretty much useless when it comes to the syntax of mod_rewrite, so I’m probably overlooking some small but key detail.
Oho my friends and compatriots, I have the final answer for you:
RewriteCond %{QUERY_STRING} ^tag=(.*)$
RewriteRule .* /tag/%1/? [R=301,L]
If you leave the ? off the end you’ll end up with an infinite rewrite because it will try to make /tag/example/?tag=example. Thanks for your help everyone!