网站根包含三个目录,a,b,c
所有目录都充当不同域的根
我在目录.htaccess
中创建了一个b
,并向其添加了以下规则
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^([^/]*)/?([^/]*)/$ /b/sample-page?bbi=$1&bbl=$2 [L]
代替上面的最后一行,我也试过
RewriteRule ^b/([^/]*)/([^/]*)$ /b/sample-page?bbi=$1&bbl=$2 [QSA,L]
使用上述规则
http://testsite.com/b/pageone.php
已成功重写为
http://testsite.com/b/pageone
但是http://testsite.com/b/sample-page.php?bbi=value1&bbl=value2
重写为http://testsite.com/b/sample-page?bbi=value1&bbl=value2
而不是
http://testsite.com/b/sample-page/value1/value2
或
http://testsite.com/sample-page/value1/value2
答案 0 :(得分:1)
您需要在其他规则中添加L
标记:
RewriteRule ^(.*)$ $1.php [L]
要处理其他情况,您需要在之前添加规则。
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/b/([^/]+)/([^/]+)/([^/]+)
RewriteCond %{DOCUMENT_ROOT}/b/%1.php -f
RewriteRule ^/?([^/]+)/([^/]+)/([^/]+) $1.php?bbi=$2&bbl=$3 [L]
这应该是这样的,当你转到http://testsite.com/b/sample-page/value1/value2
时,你会收到/b/sample-page.php?bbi=value1&bbl=value2
的内容