2010-07-05 41 views
0

我有一个问题,添加一个默认的重写PHP和HTML请求到我的apache .htaccess。我的.htaccess中的递归循环

这个想法是为我的网站上的内容设置模板,指定文件夹中的内容使用特定的模板。它适用于html,图像和其他资源;很好地将请求重写到模板。但是,我得到一个递归的问题重写请求到php资源,因为模板也是一个php资源...也许在逻辑上足够。

是否有可能将php-to-php限制为单个重写?或者我需要另一种方法?

这条规则是我的问题:

RewriteRule ^(.*).(php$) /_templates/default.php?$1.$2 [NC,L] 

下面是我的.htaccess ...

谢谢...

# Template rewrites: 
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule ^(subpages/.*) /_templates/present.php?$1 [NC,L] 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule ^(.*).html$ /_templates/default.php?$1 [NC,L] 
RewriteRule ^(.*).(php$) /_templates/default.php?$1.$2 [NC,L] 

回答

0

您可以添加的RewriteCond是这样的:

RewriteCond $1 !^_templates/ 
RewriteRule ^(.*).php$ /_templates/default.php?$1.php [NC,L,B] 

我也添加编辑B标志,因为您在查询字符串中使用反向引用。

+0

谢谢Artefacto, RewriteCond $ 1!^ _ templates/may the trick ...干杯 – 2010-07-05 19:44:56

0

您可以添加排除规则:

重写规则/_templates/default.php(.*)$ $ 0 L]

$ 0是原始请求和[L]意味着它是最后规则此请求将运行