Forum Moderators: phranque

Message Too Old, No Replies

HTACCESS code selection for 301 redirect

Optimum HTACCESS strategy for extension less URL redirect

         

new_b

2:13 am on May 20, 2011 (gmt 0)

10+ Year Member



I'm migrating a conventional (using html files) website to a Worpress (extension-less) system. Currently the files are with shtml,htm & html extensions. Other than the extension part, the URLs remain identical in the both websites.

How do I achieve a mass 301 redirect from http://example.com/page.shtml to http://example.com/page.shtml . I want it to be done to preserve the pageranks by way of 301 redirect.

I've tried both the concepts listed below, but without success. Both throws up server error message.





### Option 1

Options +FollowSymlinks
rewriteengine on
rewriterule ^(.+)\.s?html?$ http://example.com/$1 [r=301,nc]


### Option 2
Option +SymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.s?html$ [%{HTTP_HOST}...] [L,R=301]



What is the better strategy to achieve the 2 goals.

1.Redirect all http://example.com/page.shtml to http://example.com/page.shtml
2.Preserve the pagerank.

:) new_b

new_b

2:15 am on May 20, 2011 (gmt 0)

10+ Year Member



Oops... a correction


1.Redirect all http://example.com/page.shtml to http://example.com/page

g1smd

8:26 am on May 20, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I would add a preceding condition ensuring this is an external request and not the result of any internal rewrite.

Option +FollowSymLinks
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ (([^/]+/)*[^/]+)\.(s?html?)\ HTTP/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (([^/]+/)*[^/]+)\.(s?html?)$ http://www.example.com/$1 [R=301,L]


Remove the "-f" check if you have no static .(s)htm(l) files on the server. The "-f" check is very slow and uses a lot of resources.

Too late now, but there in an "owner edit" button underneath your user name. :)