views:

290

answers:

1

I just came across this: http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html --> check under "removing the query string". It states: "On many sites, the page will be displayed for both page.html and page.html?anything=anything, which hurts your SEO with duplicate content. An easy way to fix this issue is to redirect external requests containing a query string to the same uri without the query_string."

My question is... how do you test it? I added the code below:

 RewriteCond %{THE_REQUEST} ^GET\ /.*\;.*\ HTTP/
 RewriteCond %{QUERY_STRING} !^$
 RewriteRule .* http://www.mysite.com%{REQUEST_URI}? [R=301,L]

 RewriteCond %{THE_REQUEST} ^GET\ /.*\;.*\ HTTPS/
 RewriteCond %{QUERY_STRING} !^$
 RewriteRule .* https://www.mysite.com%{REQUEST_URI}? [R=301,L]

However, if I go to www.mysite.com/?anything=bla, it still shows this link in the address bar? Did I misunderstand, or was this code not suppose to redirect to mysite.com without the query string?

Also, am I right by making one for HTTP and one for HTTPS?

+4  A: 

A better approach -- supported by the major search engines -- is to have each page specify its canonical URL using <link rel="canonical">. This Google article goes into more detail.

I would be hesitant to use a redirect in the web-server, because those query parameters should have been there for a reason (and if they weren't, it would be better to fix your pages to get rid of them). Not sure why the address in your browser didn't change; I'd recommend using a tool such as Firebug or Fiddler to verify that the 301 was actually returned to your browser.

kdgregory
If the URL in the address bar didn't change, I can pretty much guarantee that you didn't get back the 301.
EricLaw -MSFT-