1

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]
4

1 に答える 1

1

変数は%{REQUEST_URI}常に で始まり、/を使用してそれと照合している^index.php/.+$ため、その条件は常に false になります

次のようなものが必要なようです。

RewriteEngine On
RewriteBase   /

RewriteCond %{THE_REQUEST} \ /index\.php/(.+)\.(jpg|txt|php)
RewriteRule ^ /%1.%2 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php/$1 [L,PT]
于 2013-11-13T02:36:38.267 に答える