Forum Moderators: phranque
I thought the following rewriterule would prevent such things from happening:
RewriteCond %{HTTP_HOST} !^www.example\.com [NC]
RewriteRule ^(.*) http://www.example.com/$1 [QSA,R=301,L]
But apparently not. I didn't think too much of it at the time, but I'm starting to see references to it from google (not in the serps, but in google alerts). Even with a rel=canonical tag it still keeps popping up.
Any ideas how I can prevent this? Has anyone seen anything else similar?
[edited by: jdMorgan at 5:36 am (utc) on Jan. 29, 2010]
[edit reason] example.com [/edit]
There was a thread asking something similar just a few days ago. Check recent posts.
I ended up grabbing the code from this thread:
[webmasterworld.com...]
However the query string remains - What would be the best way to modify this code to get it to include redirecting the query string?
#Fix canoncial issues: http://www.webmasterworld.com/apache/4069463.htm
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*index\.php\ HTTP/ [NC]
RewriteRule ^(([^/]+/)*)index\.htm$ http://www.example.com/$1 [NC,R=301,L]
#
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{HTTP_HOST} !=www.example.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} !^(www\.example\.com|0\.0\.0\.0)?$
RewriteRule ^ - [F]
#END canonical
[edited by: jdMorgan at 5:29 am (utc) on Jan. 29, 2010]
[edit reason] example.com [/edit]
As it turns out, that code isn't relevant to the problem you report. Perhaps the code in this thread [webmasterworld.com] would be more appropriate (read on to the end).
Jim
But back to the issue at hand - the other thread you referenced was exactly what I was looking for. I tried the code at the end of the thread as well as the apache 2.x code that was posted, however the query string still appears. I'm wondering if maybe I've got something else interfering with it (like wordpress).
I know it's tough to make suggestions without seeing all the code, but any idea what could conflict with such a rewrite rule?
You might want to review the recent thread about improving WordPress mod_rewrite code performance [webmasterworld.com].
Jim