I have .htaccess
file with the following directives:
RewriteEngine on
RewriteBase /amit/public/
RewriteCond ${REQUEST_FILENAME} !-f [OR]
RewriteCond ${REQUEST_FILENAME} !-d [OR]
RewriteCond ${REQUEST_FILENAME} !-s [OR]
RewriteCond ${REQUEST_FILENAME} !-l
RewriteRule ^(.*[^/])/?$ $1.php [NC,L]
Pretty basic redirection. However, I’m getting an infinite internal loop in my apache log files with a 500 error in the browser. The apache log file has the following:
r->uri = /amit/public/activities.php.php.php.php.php.php.php.php.php
redirected from r->uri = /amit/public/activities.php.php.php.php.php.php.php.php
redirected from r->uri = /amit/public/activities.php.php.php.php.php.php.php
redirected from r->uri = /amit/public/activities.php.php.php.php.php.php
redirected from r->uri = /amit/public/activities.php.php.php.php.php
redirected from r->uri = /amit/public/activities.php.php.php.php
redirected from r->uri = /amit/public/activities.php.php.php
redirected from r->uri = /amit/public/activities.php.php
redirected from r->uri = /amit/public/activities.php
redirected from r->uri = /amit/activities.php
redirected from r->uri = /activities.php
That’s when I enter the page with the extension. Makes no difference when I try to access the page without the extension. The page exists and I’ve double checked everything, but it seems to me that the main issue is the RewriteCond.
Any help is appreciated.
2
Answers
Thanks to @anubhava. I've just realized that my code uses
$
for all the server variables. It should be%
. A silly typo had hacked my brain for close to 24 hours... So the 'ultimate' code with the suggestions made by @anubhava would be:Works like a charm.
You don’t need 4 conditions and need to have them ANDed together: