0

hi i am trying to remove .html from url.

example : from: example.com/home.html to example.com/home

i ran into some videos and posts regarding .htaccess file.

i used this code for htaccess and checked it on htaccesschecker , it says syntax is ok.

RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]

i am trying to do it first on vscode. when i run live server i just get same .html ending for every html file...

1 Answer 1

3

With your shown samples please try following .htaccess rules file. Please make sure to clear your browser cache before testing your URLs.

RewriteEngine ON
##External redirect rules here.
RewriteCond %{THE_REQUEST} \s/([^.]*)\.html\s [NC]
RewriteRule ^ /%1? [R=301,L]

##Internal rewrite rules here..
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/?$ $1.html [L]
Sign up to request clarification or add additional context in comments.

1 Comment

@Hawasaki7, Did this work out for you?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.