Htaccess extensionless url question

Hi All,

I have a few questions Im hoping someone can answer

Ive written an htaccess file that removes the trailing slash from html files. This all works good. Am I doing this right? Also do I have to write “RewriteEngine on” twice based on the following code or is that overkill?

Any recommendations on adding or taking away anything from this file?

My whole goal is to write nice looking urls and avoid duplicate content to which I read that with the trailing slash and without can be treated as two different files.

My file looks like this…

ErrorDocument 404 /404page.html
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.mydomain.com$
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\\ /index\\.html\\ HTTP/
RewriteRule ^index\\.html$ http://www.mydomain.com/ [R=301,L]

Options +FollowSymLinks
RewriteEngine On

# Remove trailing slashes.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=permanent,QSA]

# Redirect to HTML if it exists.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]

Ive ran a test on the and posted the following files

www.mydomain.com/test/index.html - which goes to www.mydomain.com/test/ (note the trailing slash)
www.mydomain.com/test/test1.html - which goes to www.mydomain.com/test/test1 (note the NO trailing slash)
www.mydomain.com/test/test2.html - which goes to www.mydomain.com/test/test2 (note the NO trailing slash)

Is this how its supposed to work?

Thanks in advance.

Yes, you can remove the second RewriteEngine ON.

Also, I would probably move the Options +FollowSymLinks to the sites-enabled file instead, but that’s optional.

Otherwise I don’t see anything that shouldn’t really be there.

Though you should note that if you have a file.html and directory with the same name, it’ll be impossible to reach the file through this method. As long as that’s okay, you should be good.

wf,

First, please use the [noparse]

 ... 

[/noparse] to wrap your code.

Regards,

DK