1

I wanted to replace the .html extensions with just nothing in apache.

Eg. DNS/coffee.html to be DNS/coffee. I found myself this code.

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)/?$ $1.html [L]
</IfModule>

It does the job I wanted, but it doesn't.

It seems to not like 404.html for errors. Everytime I open a page that doesn't exist, it doesn't give me the 404 page anymore, but a 500 internal server error message:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at EMAIL to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request. Apache/2.4.41 (Ubuntu) Server at URL Port 443

I don't know what I am suposed to do, google doesn't give me wise answers, only things like “how to redirect a page to 404.html” or “how to make every link that doesn't go to this DNS reditect to 404 page.”

Here is the code for .htaccess.

# ------------------Error Pages--------------------
# 404 NOT FOUND
ErrorDocument 404 /errors/404.html
# -----------------Rem .html and .htm extensions---
 
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)/?$ $1.html [L]
</IfModule>
Giacomo1968
  • 53,069
  • 19
  • 162
  • 212

1 Answers1

0

Your non-HTML rewrite rule is negatively affecting the /errors/404.html from ever being loaded.

That results in a condition where Apache keeps on trying to load errors/[something].html and eventually loops until it dies with a 500 error.

It won’t load the 404.html page because of the sloppy logic you have here.

If someone goes to DNS/ddqqweeqewqweewq — or some other nonsense URL you know doesn’t work — your rules are then telling the server to attempt to load DNS/ddqqweeqewqweewq.html and then the resulting error loads /errors/404/ddqqweeqewqweewq.html. Which doesn’t exist.

Try adding a url a RewriteCond such as RewriteCond %{REQUEST_FILENAME} !^/errors/ above the RewriteRule like this:

# ------------------Error Pages--------------------
# 404 NOT FOUND
ErrorDocument 404 /errors/404.html
# -----------------Rem .html and .htm extensions---

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !^/errors/
    RewriteRule ^([^/]+)/?$ $1.html [L]
</IfModule>
Giacomo1968
  • 53,069
  • 19
  • 162
  • 212