Neel Bhasin
Neel Bhasin

Reputation: 759

Redirection through htaccess from non html to .html extension?

i want to add .html to my html files automatically using htaccess.

As we can remove .html very easily but i want to know can i add .html to a non html file that is located with my website. for example this is my domain

www.abc.com/name.html

but when i am accessing

www.abc.com/name

It is showing me the same page but not automatically adding the .html extension.

So i want that if i try to open www.abc.com/name then it automatically shows me www.abc.com/name.html

How to achieve this.

Thanks

Upvotes: 2

Views: 1306

Answers (1)

anubhava
anubhava

Reputation: 785128

You can use this rule:

RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule ^ https://pcsmartcare.com%{REQUEST_URI} [L,R=301] 

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

RewriteCond %{THE_REQUEST} /index\.html?\s [NC]
RewriteRule ^(.*)index\.html?$ /$1 [R=301,L,NC]

Upvotes: 1

Related Questions