【问题标题】:Apache rewrite rules with Perl backslash sequences not working使用 Perl 反斜杠序列的 Apache 重写规则不起作用
【发布时间】:2014-01-10 11:24:50
【问题描述】:

我有一个非常简单的 Nginx 重写规则:

rewrite (*UTF8)^/([\pL\pN\/-]*)$ /index.php?route=$1;

它使用 Perl 反斜杠序列来匹配所有 unicode 字母和数字。

我试图在 Apache 上重现它:

RewriteRule ^([\pL\pN\/-]*)$ /index.php?route=$1 [QSA,L]

但是它只匹配斜线和破折号。错误日志是干净的。

【问题讨论】:

    标签: regex perl apache .htaccess mod-rewrite


    【解决方案1】:

    mod_rewrite 不支持 \p 属性,但您可以将 \wBNE 标志一起使用,这会将您重写的 URI 未转义为 /index.php

    RewriteRule ^([\w/-]+)$ /index.php?route=$1 [QSA,L,B,NE]
    

    PS: \w 还包括下划线。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-20
      • 1970-01-01
      • 2011-11-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多