Recursive loop in my .htaccess
I have a problem adding a default rewrite php and html requests to my apache .htaccess.
The idea is to set up templates for the content on my site, specifying that the content in a folder uses a specific template. It works fine for html, image and other resources; requests are rewritten to the template nicely. But I get a recursive problem rewriting request to php-resources, because the template is also a php-resource… perhaps logically enough.
Is it possible to limit the php-to-php to a single rewrite? Or do I need another approach ?
This rule is my problem:
RewriteRule ^(.*).(php$) /_templates/default.php?$1.$2 [NC,L]
Below is my .htaccess...
Thanks...
# Template rewrites:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(subpages/.*) /_templates/present.php?$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*开发者_如何学JAVA).html$ /_templates/default.php?$1 [NC,L]
RewriteRule ^(.*).(php$) /_templates/default.php?$1.$2 [NC,L]
You can add a RewriteCond like this:
RewriteCond $1 !^_templates/
RewriteRule ^(.*).php$ /_templates/default.php?$1.php [NC,L,B]
I also added the B
flag because you're using the backreference in the query string.
You can add an exclusion rule :
RewriteRule /_templates/default.php(.*)$ $0 [L]
$0 is the original request and [L] means it is the last rule this request will run
精彩评论