重写多个参数.htaccess

时间:2011-02-13 07:10:59

标签: regex .htaccess mod-rewrite rewrite

我需要将www.sample.com/user/john/重写为www.sample.com/user/?u=john

这段代码只有在我遗漏尾随/“www.sample.com/user/john”的情况下才有效,我如何让它像“www.sample.com/user/john/”一样工作?

  

RewriteRule ^([A-Za-z0-9 _] +)$ index.cfm?u = $ 1 [L]

现在我需要它进一步发挥作用

www.sample.com/user/john/23564/重写如“www.sample.com/user/?u=john&i=23564”

有一件事“www.sample.com/user/john”仍然应该写出/ 23564 /

感谢

1 个答案:

答案 0 :(得分:1)

添加可选的斜杠(以及URL的“user /”部分):

RewriteRule ^user/([A-Za-z0-9_]+)/?$ index.cfm?u=$1 [L]

下一步:

RewriteRule ^user/([A-Za-z0-9_]+)(/([0-9]+))?/?$ index.cfm?u=$1&i=$3 [L]