我有以下情形:mod_rewrite的省略HTML扩展循环
两个frontcontrollers在web目录(文档根目录):
web/frontend.php # handles all *.html requests
web/backend.php # direct calls only
重写容易至今:
RewriteCond %{REQUEST_URI} !^/backend.php
RewriteRule (.+)\.html$ /frontend.php [L]
所以现在当我打电话给example.org/backend.php
时,我在后端,没有什么特别的事情发生。当我打电话给example.org/
或example.org/team/john.html
时,它由frontend.php
处理。
到目前为止!
现在我想要省略* .html扩展名的可能性,以便example.org/team/john
在内部处理为example.org/team/john.html
。
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule !.*\.html$ %{REQUEST_URI}.html [L]
最后但并非最不重要我想请求重定向到john.html
到john
,以避免重复的内容。
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} ^(.+)\.html$
RewriteRule (.*)\.html$ /$1 [R=301,L]
每一个部分都工作在它自己的,但放在一起,我得到一个循环,这并不让我感到吃惊,但我不知道该如何避免这种情况。我搜查了文档,尝试了几个旗帜和条件,但我完全陷入困境,我需要帮助。
这里是整个.htaccess文件:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase/
# extend html extension internally
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule !.*\.html$ %{REQUEST_URI}.html [L]
# redirect example.html to example
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} ^(.+)\.html$
RewriteRule (.*)\.html$ /$1 [R=301,L]
# frontcontroller
RewriteCond %{REQUEST_URI} !^/backend.php
RewriteRule (.+)\.html$ /frontend.php [L]
</IfModule>
任何帮助将是巨大的。
太棒了!谢谢! –