Htaccess question: ErrorDocument not working

SYSTEM INFORMATION
OS type and version: Ubuntu 18.04
Webmin version: 1.981
Virtualmin version: 6.17-3

I’m trying to use custom 404 page on my website. In my htaccess I added
ErrorDocument 404 /404.php
but it has no effect. I get some standard page that says “File not found”. I also tried
ErrorDocument 404 https://www.domain.com/404.php
and Services > Configure SSL website > Error handling. No result. Not sure where this page is being loaded from and how to override it.

Are you purging your caches when you make the changes?

As a test, if you post the base url of your site, someone can visit yoursite.com/ql;erkkgjwoj and see what error they get. If it’s your custom error page, then it’s working and you have a caching error.

Which cache are you referring to? I tried restarting apache after the changes and I’m using incognito window to test. My domain is notaloss (dot) com

This is the page I see for your 404 error:

OK. I just noticed what you’re talking about. It works like a charm on an html request but on some php request it’s showing the “File not found” page.

Two things:

  1. If you’re using Wordpress, try resaving your permalinks twice. That usually sorts that out.
  2. Make sure you have rewrite engine on.

Ex:
RewriteEngine on
ErrorDocument 404 /404.php

Thanks for checking that out. Yes indeed .html pages work like they’re supposed to.

I have this code as well to remove .php extension from URLs. Surely this must be the reason. Posting entire htaccess

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]

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

ErrorDocument 404 /404.php

That should work. Yeah. That’s weird.

When I comment out this part

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

it works properly. :thinking:

Any idea where the “File not found.” comes from? What’s virtualmin/apache ultimately resolving this to?

Bump.

Everything works normally on localhost (xampp). Its virtualmin acting up here. Can someone suggest possible causes?

do it on Apache directories level or configs level… htaccess would not work on virtualhost level, that’s why it does work on local host not on virtualhost