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.php
etc.
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]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.