HTACCESS重写不能超过2个参数

时间:2014-07-23 14:33:05

标签: .htaccess mod-rewrite url-rewriting

好的。这是我的htaccess代码:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ bank.php?bank=$1
#This will make my url e.g. site.com/citibank

RewriteRule ^(.*)/(.*)$ state.php?bank=$1&state=$2
#This will make my url e.g. site.com/citibank/new-york

RewriteRule ^(.*)/(.*)/(.*)$ location.php?bank=$1&state=$2&district=$3
#This will make my url e.g. site.com/citibank/midtown

问题:它的工作直到第二条规则,但是当涉及到第三条也是最后一条规则时,它创建了网址:site.com/bank.php/citibank/new-york

任何帮助将不胜感激。 感谢

1 个答案:

答案 0 :(得分:1)

这是因为您的第一条规则是使用.*模式并匹配所有内容。将您的代码更改为:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/?$ bank.php?bank=$1 [L,QSA]
#This will make my url e.g. site.com/citibank

RewriteRule ^([^/]+)/([^/]+)/?$ state.php?bank=$1&state=$2 [L,QSA]
#This will make my url e.g. site.com/citibank/new-york

RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ location.php?bank=$1&state=$2&district=$3 [L,QSA]
#This will make my url e.g. site.com/citibank/midtown