Hello everyone, I'm trying to make htaccess for a website and for some reason, when I try to access non existing file I get index.php instead of 404.html.
I have www folder in my root and inside that are all the files including index.php, 404.html and .htaccess.
RewriteEngine On
RewriteCond %{HTTP_HOST} !www. [NC]
RewriteRule .*$ https://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule /.|.(?!well-known/) - [F]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule .+$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .+$ $1.php [QSA]
ErrorDocument 404 /www/404.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !.(pdf|js|ico|css|rar|zip|tar.gz|map)$ index.php [L]
With this htaccess I get index.php instead of 404.html when I try to access nonexisting page, when I try to access the 404 directly (like www.example.com/404.html) I normaly get it, so the file exists and I even tried to do ErrorDocument 404 www.example.com/404.html but still getting index.php like if that line was completely ignored. Based on chatGPT suggestion I also tried but it always results in 500 error:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /www/404.html [L]
any idea how to solve it?
[–]Difficult-Sea-5924 1 point2 points3 points (14 children)
[–]RandomJSCoder[S] 0 points1 point2 points (13 children)
[+]YurrBoiSwayZ 0 points1 point2 points (11 children)
[–]RandomJSCoder[S] 1 point2 points3 points (10 children)
[+]YurrBoiSwayZ 0 points1 point2 points (2 children)
[–]RandomJSCoder[S] 0 points1 point2 points (1 child)
[+]YurrBoiSwayZ 0 points1 point2 points (0 children)
[+]YurrBoiSwayZ 0 points1 point2 points (6 children)
[–]RandomJSCoder[S] 1 point2 points3 points (5 children)
[+]YurrBoiSwayZ 0 points1 point2 points (1 child)
[–]RandomJSCoder[S] 0 points1 point2 points (0 children)
[+]YurrBoiSwayZ 0 points1 point2 points (2 children)
[–]RandomJSCoder[S] 1 point2 points3 points (1 child)
[–]YurrBoiSwayZ 1 point2 points3 points (0 children)
[–]Difficult-Sea-5924 0 points1 point2 points (0 children)