Forum Moderators: phranque
^example\.com in the Condition, it should test for !^(www\.example\.com)?$ to ensure all non-canonical requests are redirected. RewriteCond testing THE_REQUEST otherwise you end up with an infinite loop of redirecting and rewriting. As this question comes up every few days, it should be easy to find the code already posted here. [R=permanent,L] into [R=301,L]
I am not sure if the trailing slash should be the main target or the .com should be the main target.
www.example.com/ RewriteCond %{HTTP_HOST} !{et cetera as already explained}
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
^(([^/]+/)*)index(\.(php|html?))?$ ^(([^/]+/)*)index\.(php|html?)?$ wrong-form-of-domain-name/optionalblahblah/index.html I actually have this coding <snip> to "create" extensionless urls.
href="/page" GET /page HTTP/1.1 /public_html/site_name/www/page /public_html/site_name/www/page.php just before Apache attempts to fetch content. www.example.com/page.php with extension hence leaving you with a Duplicate Content problem to solve. /page.php to www.example.com/page and you do that with a RewriteRule for the redirect and a preceding RewriteCond testing THE_REQUEST to be sure this was an external request for /page.php and not an internal request as a result of a previous rewrite. index.html and index.php requests on any hostname to root ("/") or to folder ("/folder/") on www .php requests on any hostname to extensionless on www non-www to www .php file RewriteRule. The 3 redirects will each have a preceding RewriteCond (testing different things each time). The rewrite is a single line of code. RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]
RewriteRule ^directory/index\.php$ http://www.example.com/directory/ [R=301,L]
RewriteCond %{THE_REQUEST} index\.php
RewriteRule ^(([^/]+/)*)index\.php http://www.example.com/$1 [R=301,L] RewriteRule ^(.*)\.php/$ http://www.example.com/$1 [R=301,L] ^([^.]+)\.php