带参数的apache重写规则

时间:2011-04-11 16:29:25

标签: apache mod-rewrite url-rewriting rewrite

我有以下网址:

http://www.domain.com/results.php?state=WA&city=Seattle&sub=algebra

我希望它显示为:

http://www.domain.com/results/WA/Seattle/algebra

和...

http://www.domain.com/results.php?state=WA&city=Seattle

作为

http://www.domain.com/results/WA/Seattle

我想我可以把第一个写成:

RewriteRule ^results/(.*)/(.*)/(.*)$  /results.php?state=$1&city=$2&sub=$3 [L]

但是我不知道如何将它们两者结合起来......斜线让我失望。有什么建议吗?

1 个答案:

答案 0 :(得分:1)

RewriteRule ^results/([^/]+)/([^/]+)/([^/]+)$  /results.php?state=$1&city=$2&sub=$3 [L]
RewriteRule ^results/([^/]+)/([^/]+)$ /results.php?state=$1&city=$2