I'm setting up a 404 page on a project on my localhost (MAMP) and in my .htaccess
file I’ve included the following code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+) $1.php [NC,L]
</IfModule>
ErrorDocument 404 http://localhost:8888/project/public/404.php
The 404.php page sits at the same level as .htaccess
file in a public folder below the project root:
project
— publicFolder
— privateFolder
The Issue
When I include the code within the <IfModule mod_rewrite.c>
it throws an error when I type in a 404 page URL (i.e. a page that doesn't exist). When I remove this <IfModule mod_rewrite.c>
code block the problem goes away. The error message is:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at you@example.com to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
When I check the apache error log, as recommended in the above message I get the following:
[core:error] [pid 2575] [client ::1:51038] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
I suspect the issue may be to do with the line that removes the .php
file extension on all of the pages, i.e.RewriteRule (.+) $1.php [NC,L]
My Question
How do I get the clean URL code inside the <IfModule mod_rewrite.c>
block to stop throwing an internal server error when a user goes to what should be a 404 page?
Any help great appreciated.