htaccess和urlencoded变量

时间:2012-01-26 22:58:21

标签: .htaccess url mod-rewrite rewrite urlencode

以下是点击网站上的按钮时传递的URL的示例。

http://www.site.com/account/messages/compose/316/&sbj=Web+Programmer+%2F+Developer&event=836

这就是我对重写规则的要求:

RewriteRule ^account/messages/compose/([0-9]+)/(.*)/([0-9]+)/?$ index.php?m=account_messages&p=compose&id=$1&sbj=$2&event=$3 [L]

id和event始终是数字,但是subj can是url编码的字符串 因为它现在不起作用

1 个答案:

答案 0 :(得分:0)

您的网址是否遗漏了?,即它应该是http://www.site.com/account/messages/compose/316/?sbj=Web+Programmer+%2F+Developer&event=836

将以下内容添加到站点根目录中的.htaccess文件中。

由于sbjevent已经在查询字符串中,QSA标志会自动传递它们,即它会重写

  

http://www.site.com/account/messages/compose/316/?sbj=Web+Programmer+%2F+Developer&event=836

相当于

  

http://www.site.com/index.php?m=account_messages&p=compose&id=316&sbj=Web+Programmer+%2 F +开发人员&安培;事件= 836

RewriteEngine on
RewriteBase /

RewriteRule ^account/messages/compose/([0-9]+)/$ index.php?m=account_messages&p=compose&id=$1 [L,QSA,NC]