Mobile app version of vmapp.org
Login or Join
Carla537

: Trouble reading htaccess canonicalization 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.

@Carla537

Posted in: #Htaccess #ModRewrite

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: 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$ www.example.com/%1 [R=301,L]

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

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Carla537

1 Comments

Sorted by latest first Latest Oldest Best

 

@Heady270

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 example.com or 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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme