我在 Nginx 上有一个非常简单的重写规则:
rewrite (*UTF8)^/([\pL\pN\/-]*)$ /index.php?route=$1;
它使用 Perl 反斜杠序列来匹配所有 unicode 字母和数字。
我试图在 Apache 上复制它:
RewriteRule ^([\pL\pN\/-]*)$ /index.php?route=$1 [QSA,L]
但是它只匹配斜杠和破折号。错误日志很干净。
最佳答案
mod_rewrite
不支持 \p
属性,但您可以将 \w
与 B
和 一起使用>NE
标志,它将向您发送未转义的重写 URI 到 /index.php
:
RewriteRule ^([\w/-]+)$ /index.php?route=$1 [QSA,L,B,NE]
PS: \w
也包括下划线。
关于regex - 使用 Perl 反斜杠序列的 Apache 重写规则不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20723271/