Forum Moderators: phranque
I am trying to do a simple 301 from
http://www.example.com/?cat=1
to
http://www.example.com/1
so far I have
RewriteEngine On
RewriteBase /
RewriteRule ^\?cat=([0-9]+)$ /$1 [R]
Thanks for the help!
RewriteEngine on
#
RewriteCond %{QUERY_STRING} cat=([0-9]+)
RewriteRule ^$ http://www.example.com/%1 [R=301,L]
Example:
example.com/12345?cat=12345
also, if I try example.com/index.php?cat=12345 as the URL it doesn't redirect either. Strange.
What's going one here!?
Thanks.
[edited by: CWebguy at 4:00 pm (utc) on Mar. 10, 2009]
A question mark at the end of the rewrite URL seems to clear the query. (I'm hoping)
RewriteRule ^$ http://www.example.com/%1? [R=301,L]
Still doesn't work for index.php?ca=12345, wonder if index.php is considered part of the query?
I also seem to have to put the .htaccess file in each sub folder or it won't even work correctly, wonder if this is a server config error. Thanks.
CWebguy
[edited by: CWebguy at 4:28 pm (utc) on Mar. 10, 2009]
Fix it by using the index.php-stripping 301 redirect that has been posted in 4 or 5 threads in recent days. That is, you do NOT invoke the rewrite for multiple alternative URLs, you redirect all the alternative URLs to the canonical form of your choosing (presumably with www and without index.php included). This index redirect goes before your general non-www to www redirect.
Note also, that all of the various redirects must be listed before you list any rewrites.
[edited by: g1smd at 5:00 pm (utc) on Mar. 10, 2009]