I just took over development of a site and am having trouble figuring out the canonicalization rewrite rules (not my forte). I've pasted the code below.

The first bit seems straight-forward enough, stripping out index.html. The second part redirects non-www TO www and also appears to be redirecting to NO trailing slash: www.example.com (no "/"). I actually can't confirm the trailing slash part though (header sniffers don't show the / redirect).

Is there a trailing slash redirect in place? (btw, this code is years old, so am open to better, more efficient options).

RewriteEngine on 
RewriteBase / 

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

# Redirect TO WWW with no trailing slash? 
RewriteCond %{HTTP_HOST} !^www\.example\.com 
RewriteRule (.*) http://www.example.com/$1 [R=301,L] 

1 Answer 1


For a domain name, there is no way on the server side to control the trailing slash. (This is opposed to directories, where it is up to the server to manage the trailing slash.) This is because of the way that the HTTP protocol works. Every request must start with a slash. So the request for the home page of a site always looks like this, regardless of whether link is http://example.com or http://example.com/

GET / HTTP/1.1
Host: example.com

As a result, it is the browser that manages the trailing slash on the domain name. Nowadays, most browsers automatically put it in. There is nothing you can do server side to control whether a trailing slash appears at the end of your domain name.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.