Page is a not externally linkable
- Code, Content, and Presentation
-- Apache Web Server
---- Canonicalization: best code to redirect no-www to www & index to /


ewwatson - 9:00 am on Oct 16, 2012 (gmt 0)


Ok well explained. Thank you! For good measure I'm going to show here how I interpreted what you said. Is this correct? And can I assume I can safely do away with the php part in the main domain (only has html extensions) as long as I include php in the addon domain code (they have php extensions)?

Main domain...

# Engine on only needed once
RewriteEngine On

# Redirect index.html, .htm and .php to folder
RewriteCond %{HTTP_HOST} !(example\.net|example\.org|example\.co\.uk)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.(html?|php)\ HTTP/
RewriteRule ^(([^/]+/)*)index\.(html?|php)$ http://www.example.com/$1 [R=301,L]

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

and Addon domains...

# Engine on only needed once
RewriteEngine On

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

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


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