htaccess重写规则3变量

时间:2014-02-20 11:32:00

标签: regex apache .htaccess mod-rewrite

RewriteRule ^albums/([^/.]*)/?$ albums.php?user=$1&name=$2 [L,QSA]
RewriteRule ^albums/([^/.]*)/([^/.]*)/?$ albums.php?user=$1&name=$2&album_id=$3 [L,QSA]

original
albums.php?user=123&name=foo&album_id=456

result
albums/123/foo/456

我有一个htaccess重写url,我需要设置3个get变量,但这段代码不能正常工作

任何人都知道如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

你的正则表达式错了。您可以使用:

#For 3 variables:
RewriteRule ^albums/([^/.]+)/([^/.]+)/([^/.]+)/?$ albums.php?user=$1&name=$2&album_id=$3 [L,QSA]

# for 2 variables:
RewriteRule ^albums/([^/.]+)/([^/.]+)/?$ albums.php?user=$1&name=$2 [L,QSA]