So I have a website and I want it to redirect to a custom 404 page I made when it gets a 404 status, so this is inside my .htaccess
file:
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/$ $1.php RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !(.[a-zA-Z0-9]{1,5}|/)$ RewriteRule (.*)$ /$1/ [R=301,L] Options -Indexes ErrorDocument 404 https://domainname.com/404.html
Which also contains code to remove the extensions to be able to go to a page like this domain/file
without having to specify the trailing extension and Options -Indexes
to disable directory browsing. Now when I go on a page that does not exist I get this page:
(PS: I’m using brave browser thus the presence of the wayback machine prompt)
Failed to load resource: the server responded with a status of 404 ()
But it does not redirect to my 404 page as specified in my .htaccess file
.
Any idea?
Thanks in advance.
Advertisement
Answer
I fixed it by adding
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
and replaced Options -Indexes
by Options All -indexes
.
to the top of .htaccess
file.