我正在为 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]