Question

I have the following .htacess file to remove the .php extension and to create SEO Friendly URLs:

RewriteEngine On 

ErrorDocument 404 /404.php

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.+)\.php$ /$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ index.php?page=$1 [L]

This works absolutely fine when hosted on our domain, but when I test locally on our localhost server it comes up with Error 500, Internal Server Error.

In my httpd.conf file, the rewrite module is uncommented:

LoadModule rewrite_module modules/mod_rewrite.so

The Apache Error Log states:

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., referer: http://localhost:8888/Website/

Any ideas?

Was it helpful?

Solution

Yes this is definitely due to looping.

Your first rule is removing .php extension. Then 404 handler and 2nd rule is sending everything to .php files hence looping will go on.

To avoid you can use these rules:

RewriteEngine On 
RewriteBase /Website/

ErrorDocument 404 /Website/404.php

RewriteCond %{THE_REQUEST} \s/+/Website/(.+?)\.php[\s?] [NC]
RewriteRule ^ %1 [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ index.php?page=$1 [L,QSA]

Note use if %{THE_REQUEST} instead of RewriteRule. THE_REQUEST variable represents original request received by Apache from your browser and it doesn't change by application of other rules.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top