3

Trying to remove .html extensions from the site using .htaccess. So for example: www.mysite.com/charts.html would become www.mysite.com/charts

The following script is in the .htaccess file:

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

But when the url without the .html extension is entered in the browser, it shows a 403 Forbidden error. Any help would be appreciated.

1
  • Would we have to create a conf file? Looked around and don't see a conf file anywhere in our server files.
    – RMX
    May 20, 2012 at 21:25

1 Answer 1

7

I found this solution elsewhere:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

sources: 1) http://www.catswhocode.com/blog/10-useful-htaccess-snippets-to-have-in-your-toolbox 2) http://eisabainyo.net/weblog/2007/08/19/removing-file-extension-via-htaccess/

3
  • I've tried all of the different scripts they had on that website but none seem to work and the 403 error keeps coming up.
    – RMX
    May 20, 2012 at 20:47
  • Got it working with this script after removing a folder with the same html file name. Thanks.
    – RMX
    May 21, 2012 at 0:02
  • Worked. Thanks!
    – joshiki
    Jan 10, 2022 at 1:34

Your Answer

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

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