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


g1smd - 9:51 pm on Oct 15, 2012 (gmt 0)


1a) The
\.html? pattern matches both .html and .htm requests. Redirect both. I actually use \.(html?|php)$ or \.(html?|php[45]?)$

1b) The
? after hostname paired with !^ and $ stops an infinite redirect loop for pure HTTP/1.0 requests. Pure HTTP/1.0 requests do not include a host header.

2) The
^example\.com$ pattern doesn't allow a redirect for requests for example.com:80 or www.example.com:80 nor many other non-canonical hostnames.

The code above redirects all requests when the requested hostname is not "exactly" www.example.com all in lower case.

3) The
(.*) is greedy and captures "everything" so you don't need to tell it start at the beginning and continue to the end. It does that on its own.

[edited by: g1smd at 9:59 pm (utc) on Oct 15, 2012]


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