htaccess RewriteRule特殊字符

时间:2013-11-04 10:59:04

标签: regex apache .htaccess mod-rewrite

我有这行代码:

RewriteRule ^account/?edit=([A-Za-z]+)$ /?goTo=account&act=edit_$1 [L,NC]

当我转到mysite.com/account/?edit=username时,它应该引用mysite.com?goTo=account&act=edit_username,但给我错误404

任何帮助?
谢谢!

1 个答案:

答案 0 :(得分:2)

您无法使用RewriteRule匹配QUERY_STRING。这需要RewriteCond这样:

这应该有效:

RewriteCond %{QUERY_STRING} (?:^|&)edit=([^&]*) [NC]
RewriteRule ^account/?$ /?goTo=account&act=edit_%1#something [L,NC,NE,QSA]

参考:Apache mod_rewrite Introduction

相关问题