Gmail电子邮件地址的RewriteRule

时间:2018-04-15 18:53:19

标签: apache mod-rewrite

我试图为取消订阅的网址创建重写规则以便网址

https://example.com/unsubscribe/myemail@example.com/

将重新写入

https://example.com/unsubscribe.php?email=myemail@example.com

在过去,我总是使用以下规则,没有任何问题

ReWriteRule ^unsubscribe/(.*)/?$ /unsubscribe.php?email=$1 [NC,L]

然而,在最近测试时,似乎正在取代" +"字符(通常用于gmail标记,例如" myemail+spam@example.com"),空格,创建与用户输入的电子邮件地址不同的电子邮件地址。这是个问题。你可以在这里看到一个例子:

Example Rewrite Rule Processing

我真的不知道为什么这会发生在"(。*)"过滤器应该允许任何次数的任何字符,不应该吗?

任何建议都将不胜感激。

1 个答案:

答案 0 :(得分:1)

您可以在规则中使用mod-rewrite B标志:

ReWriteRule ^unsubscribe/(.*)/?$ /unsubscribe.php?email=$1 [NC,L,B]

从apache mod-rewrite flag手册:

The [B] flag instructs RewriteRule to escape non-alphanumeric characters before applying the transformation. In 2.4.26 and later, you can limit the escaping to specific characters in backreferences by listing them: [B=#?;]. Note: The space character can be used in the list of characters to escape, but it cannot be the last character in the list. mod_rewrite has to unescape URLs before mapping them, so backreferences are unescaped at the time they are applied