【发布时间】:2013-11-25 11:30:02
【问题描述】:
我正在为 mod_rewrite 做一个非常简单的规则,但我得到了一个循环 以下是规则:
首先,如果我有类似的要求
index.php/SOMETHING.(txt,jpg,php)
我需要先检查/SOMETHING.(txt,jpg,png)是否存在并显示
如果文件不是index.php/SOMETING 并且是存在的真实路径,则显示它
如果不是...将其传递给index.php/SOMETHING.(txt,jpg,php) 并显示 index.php
如果我有一个不存在的 txt、jpg、php,这一切都有效,但最后一条规则
示例:http://domain.com/index.php/robots1.txt
文件不存在:/Applications/XAMPP/xamppfiles/htdocs/testredir/robots1.txt
适用于任何其他扩展...
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^index.php/.+$
RewriteRule ^index.php/(.+)\.jpg$ $1.jpg [NC,L]
RewriteRule ^index.php/(.+)\.txt$ $1.txt [NC,L]
RewriteRule ^index.php/(.+)\.php$ $1.php [NC,L]
#here I am missing a rule but if i put the following it will loop
#RewriteCond %{REQUEST_URI} -f
#RewriteRule .* index.php/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^index.php/.+$
RewriteRule .* index.php/$0 [PT]
【问题讨论】:
标签: apache mod-rewrite url-rewriting apache2