apache - .htaccess 重写规则不会使用 unicode 字符

标签 apache .htaccess mod-rewrite url-rewriting

我正在使用以下 ModRewrite 使我的 url 看起来更干净:

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?key=$1

它允许很好地使用字母和数字,但是当我尝试使用 % 时会产生 400 错误,我需要使用 unicode 字符来表示 #/' 等。 这背后有什么原因吗?谢谢。

最佳答案

您应该在重写规则中使用 B 标志。看看apache manual .

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-#$%^&]+)/?$ index.php?key=$1 [B]

编辑: mod_rewrite 使用非转义字符,所以如果你想使用 unicode 字符,请在重写规则中使用它们并以 unicode 保存 .htaccess 文件!

关于apache - .htaccess 重写规则不会使用 unicode 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7946003/

相关文章:

Django + Apache,浏览器总是加载并且没有收到任何数据

php - 为什么这个 htaccess 文件在 wamp 服务器中不起作用

php - 使用 htaccess 将所有重定向到 index.php

apache - Htaccess : URL Rewriting not causing 404 on nonexisting pages and not working as expected

.htaccess - mod_rewrite 导致排名下降

java - JSP 中的 while 循环执行 javascript 不起作用?

Apache mod_rewrite

php - URL 中的反斜杠有什么用?

regex - .htaccess URL 重写跳过其他/

php - 将所有请求重定向到非 www ssl https