.htaccess - 301 redirect all files without extension to have .html extension

I need 301 redirecting file requests without an extension to it with the .html extension added:

http://www.mydomain.com/this

to

http://www.mydomain.com/this.html

The following will not be redirected:

http://www.mydomain.com/that/ (it a directory)
http://www.mydomain.com/other.php

Any help that was rated higher, thanks.

+5
source share
1 answer

Try the following. I would put it as the last rule in your set (i.e. Bottom), so as not to conflict with any other rules.

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\..+$
RewriteRule ^(.*)$ /$1.html [R=301,L]

This should ensure that the request is not a directory, and that this does not end with any extension. If these conditions are met, he will add a query using .html.

, , .;)

+5

All Articles