我想要这样的网址:localhost/dir/subdir/index.php?folder=images&picture=pic1.jpg
重写为:localhost/dir/
所以我在RewriteEngine On
RewriteRule ^(.*)/(.*)$ subdir/index.php?folder=$1&picture=$2 [L]
中添加了非常简单的.htaccess文件:
folder='images'
并希望在picture='pic1.jpg'
中获得localhost/dir/subdir/index.php
和folder='subdir'
,而是picture='index.php'
和RewriteEngine On
RewriteRule ^(.*)/(.*)$ index.php?folder=$1&picture=$2 [L]
奇怪的是,当我修改.htaccess文件以从同一目录(而不是'subdir')调用index.php时,它运行良好:
folder='images'
我在picture='pic1.jpg'
脚本
localhost/dir/index.php
和{{1}}
答案 0 :(得分:1)
这种情况正在发生,因为您的重写规则正在循环并将目标字符串subdir/index.php
与模式.*/.*
匹配。
使用此条件停止循环:
RewriteEngine On
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/(.*)$ subdir/index.php?folder=$1&picture=$2 [L]