fairydragon
fairydragon

Reputation: 146

Getting a 404 with htaccess

I am hoping somebody can help me with this.

I have a htaccess file in my public html folder for my website with the following:

RewriteEngine on
RewriteRule (.+)\.html$ /$1 [L,R=301]

So when I visit my site to newsletter.html it redirects to domain.co.uk/newsletter instead of domain.co.uk/newsletter.html which is what I want.. but i also get a 404 saying the page cant be displayed. The webpage in question is named newletter.html in my file manager.

Does anyone know why it cant be displayed?

Upvotes: 1

Views: 36

Answers (1)

anubhava
anubhava

Reputation: 785128

To hide .html extension use this code in root .htaccess:

RewriteEngine on

RewriteCond %{THE_REQUEST} \s/+(.+?)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=302,L,NE]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.html -f [NC]
RewriteRule ^(.+?)/?$ /$1.html [L]

Upvotes: 1

Related Questions