0
votes

I edited my htaccess file to rewrite mysite.com/page to mysite.com/page.php and to show 404 error page if a user requested mysite.com/page.php instead of mysite.com/page

I also added my own custom 404 error page

But when I requested mysite.com/page.php, the error page shown was Apache default 404 error page (instead of my custom error page), with additional error info:

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

My error log:

Request exceeded the limit of 10 internal redirects due to probable configuration error.

Here is my htaccess file:

RewriteEngine On
RewriteBase /

RewriteRule ^([^.?]+)$ %{REQUEST_URI}.php [L]

RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$"
RewriteRule .* - [L,R=404]

ErrorDocument 404 /error/404

I have tried changing 404 at the last line above to 404.php but the custom error page still not showing up..

However, the custom error page did show up when I requested mysite.com/page/ (notice the slash).

2

2 Answers

1
votes

I don't understand, where this error comes from. But you can resolve it by exiting the rule chain when 404.php is requested. Insert this rule at the beginning

RewriteRule ^error/404.php$ - [L]

Unrelated, but you can simplify your rules a little bit

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_FILENAME}.php [L]

RewriteCond %{THE_REQUEST} \.php
RewriteRule \.php$ - [L,R=404]
0
votes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php
ErrorDocument 404 /error/404.php