Whenever I have RewriteEngine on my ErrorDocument - part is not working. This is my current .htacces file:
ErrorDocument 404 404.php
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /$1.php [QSA,L]
So when I open a not existing file in my browser, I get a 500 Internal Server Error and I am not getting redirected to the 404.php - file.
Please help me ;)
This is because you're blindly rewriting the .php to the end of the URI. Let's take a look to see what happens when you go to a 404 URL:
http://example.com/blahblah!-f)!-d)(.*). .php/blahblah.php!-f)!-d)(.*). .php/blahblah.php.php!-f)!-d)(.*). .php/blahblah.php.php.phpetc.
You need to make sure what you're rewriting to actually exists or you cause a loop:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f
RewriteRule ^(.*)$ /$1.php [QSA,L]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With