1

网站根目录包含三个目录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
4

1 回答 1

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

于 2012-10-05T19:54:42.660 回答