.htaccess - ADD www. & REMOVE .html

Viewed 87

Hi! My english is not very good, sorry for any spelling mistakes.

Using .htaccess I want to add www. and remove/hide the .html.

It should look something like this:

BEFORE -- http://example.com/whatever.html

AFTER ----- http://www.example.com/whatever

I have .www adder:

RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1

And .html remover

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [N]

How to connect them?

NOTE: It want remove/hide .html from each .html file on my page.

I use this tool to test my .htaccess file: https://htaccess.madewithlove.be

Thanks for any help.

1 Answers

Could you please try following, based on your shown samples only. please make sure you clear your browser cache before testing your URLs. As per Mr.White's nice suggestion added condition in RewriteRule part to avoid passing css or js files to rule.

RewriteEngine ON
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule !\.\w{2,4}$  http://www.%{HTTP_HOST}%{REQUEST_URI}.html [L]
Related