Skip to content
Advertisement

htaccess misconfiguration 500

So basically i created a .htaccess file which removes .html extension and redirects /file.html to /file but when i write /file.html/ it causes a 500 internal server error, How can I map/file.html/ to my custom error page ? or simply redirect that also to /file.html

Here is the code :

Options -Indexes
ErrorDocument 404 /custom404.html
ErrorDocument 403 /custom404.html
ErrorDocument 500 /custom404.html


RewriteEngine on



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

Advertisement

Answer

With your shown samples, could you please try following(comments have been added in rules for explanation). Please make sure to clear your browser cache before testing your URLs.

Options -Indexes
ErrorDocument 404 /custom404.html
ErrorDocument 403 /custom404.html
ErrorDocument 500 /custom404.html

RewriteEngine on
##Added additional condition to make sure this runs from external request only.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{THE_REQUEST} s/.*.htmls [NC]
RewriteRule ^(.*).html/?$ /$1 [R=301,L,NC]

##Simply rewrite from non-existing pages to html files.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^(.*)/?$ $1.html [L]
Advertisement