Page is a not externally linkable
- Code, Content, and Presentation
-- Apache Web Server
---- 301 redirect best practice


kellyman - 8:12 am on Sep 7, 2012 (gmt 0)


Ok so pretty much there i think, just a little unsure if #30 comes last because if anywhere else it would result in a unwanted redirect

Really appreciate the input guys,

so on the old server we have this, i have put the redirect as the last call on the old server, hope i understood this correctly

RewriteEngine on


# 31 - Redirect index requests on new server
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index(\.(php|html?))?
RewriteRule ^(([^/]+/)*)index(\.(php|html?))?$ http://www.example.com/$1? [R=301,L]

# 32 - Redirect .php requests to extensionless URL
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*[^/.]+)\.php
RewriteRule ^(([^/]+/)*[^/.]+)\.php$ http://www.example.com/$1? [R=301,L]

# 30 - Redirect to new site
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

and new server we have this

# 31 - Redirect index requests on new server
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index(\.(php|html?))?
RewriteRule ^(([^/]+/)*)index(\.(php|html?))?$ http://www.example.com/$1? [R=301,L]

# 32 - Redirect .php requests to extensionless URL
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*[^/.]+)\.php
RewriteRule ^(([^/]+/)*[^/.]+)\.php$ http://www.example.com/$1? [R=301,L]

# 33 - Redirect non-canonical requests to www
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]


Thread source:: http://www.webmasterworld.com/apache/4491893.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com