带有mod_rewrite的友好URL

时间:2012-09-21 15:52:43

标签: url mod-rewrite url-rewriting

我想转换以下网址:

http://localhost/index.php?foo=bar&bar=foo

分为:

http://localhost/index/bar/foo

换句话说,我想用正斜杠替换页面扩展名,然后递归重写一个或多个变量。

这可能吗?

1 个答案:

答案 0 :(得分:0)

# to redirect the browser to friendly
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?foo=([^&]+)&bar=([^&\ ]+)
RewriteRule ^ /index/%1/%2? [L,R=301]

# to internally rewrite friendly back to the proper resource
RewriteRule ^/?index/([^/]+)/([^/]+)$ /index.php?foo=$1&bar=$2 [L,QSA]