1

Below is the code that I'm using on a .htaccess page in order to get rid of the ".html" at the end of the URL. It works fine on all pages except for one. Would any of the code on that one page be interfering with this code?

If anyone has any advice on how I'd be able to get rid of the ".html" on the URL using a MAMP server, it'd be much appreciated. Just so you know, I'm using a MAC with version 12.4 of Monterey.

Options +MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /(.*)\.html($|\ )
RewriteRule ^ /%1 [L,R=301]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ /$1.html [L]
1
  • 1
    Would you care to share which URL does not work ? Aug 13, 2022 at 12:07

2 Answers 2

0

This (supplied by others here) works for me

RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^(?!.+\.\w{2,4})(.+)$ $1.html [L]
2
  • That doesn't solve the issue. I'm getting an "Index of /" error message. Would any code in either of the files be blocking each other out?
    – Richard
    Aug 13, 2022 at 7:23
  • @Richard - it`s unlikely that the contents of the file would do this. Unless you have redirects in there. Aug 13, 2022 at 12:05
0

You can use the following code to remove .HTML extension from URL,

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.