Forum Moderators: phranque
The [QSA] is required as we want variables to be displayed and indexed by search engines, e.g. index.html?substring=shaver
Without the 301 clause all redirections are flagged as 302 Temporary Redirects, which is highly undesirable in SEO terms.
Any help would be greatly appreciated.
---------- .htaccess ----------
DirectoryIndex index.php
AddType text/css .css
AddType text/x-server-parsed-html .html
AddType text/x-server-parsed-html .htm
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ gb/index.html [R=301,QSA,L]
RewriteRule ^(.*)/index\.html$ home.php?sl=$1 [QSA,L]
RewriteRule ^index\.html$ home.php [QSA,L]
RewriteRule ^(.*)/product/(.*)\.html$ product.php?productid=$2&sl=$1 [QSA,L]
RewriteRule ^(.*)/category/(.*)\.html$ home.php?cat=$2&sl=$1 [QSA,L]
RewriteRule ^(.*)/pages/(.*)\.html$ pages.php?pagecode=$2&sl=$1 [QSA,L]
RewriteRule ^(.*)/(.*)\.html$ help.php?section=$2&sl=$1 [QSA,L]
P.S I just signed up for subscription to the Private Forums but cannot access them.
Welcome to WebmasterWorld!
RewriteRule ^([^/]+)/([^.]+)\.html$ http://www.example.com/help.php?section=$2&sl=$1 [R=301,L]
RewriteRule ^([^/]+)/([^.]+)\.html$ http://www.example.com/help.php?section=$2&sl=$1 [QSA,R=301,L]
RewriteRule ^([^/]+)/([^.]+)\.html$ /help.php?section=$2&sl=$1 [L]
Jim
Thanks for the information, it was extremely useful and got me really thinking.
I just checked the HTTP responses to the rewritten URL's on our site and they all come back with "HTTP/1.1 200 OK".
If I understand correctly, you are saying that an internal redirect that returns a 200 response code is better for search engine optimisation than an external 301/302 redirect.
If you send a 301 or 302 redirect response to search engine robot, you must expect that it will delete the first URL that it requested, and replace it's database entry with the URL given in the redirect response.
Since the goal of search-engine-friendly URLs is to avoid having search engines 'see' any dynamic URLs, redirecting to a dynamic URL defeats the whole purpose.
My main point, however, is that many webmasters try to do this friendly-URL thing backwards, believing that mod_rewrite can change the URLs that appear on their pages. Since it is a 'URL-to-filename translator' process and not a 'page content output filter,' it cannot do this.
Jim
However, Google has already indexed the masked URL's.
How do I reverse the following redirect and add a 301 clause?
RewriteRule ^(.*)/product/(.*)\.html$ product.php?productid=$2&sl=$1 [QSA,L]