htaccess的重写规则不会UNI code字重写、规则、htaccess、UNI

2023-09-02 11:25:56 作者:决定忘记你╰╮

我用下面的ModRewrite使我的网址看起来更清洁的:

I am using the following ModRewrite to make my urls look cleaner:

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

它允许使用字母和数字就好了,但它会产生一个400错误,当我尝试使用%,我需要使用UNI code字符#/',等等。 这背后的任何原因?谢谢你。

It allows use of letters and numbers just fine, but it produces a 400 error when i try to use %, which I require to use unicode characters for # / ', etc. Any reason behind this? Thanks.

推荐答案

你应该使用 B 标记中的重写规则。看看阿帕奇手动。

you should use B flag in your rewrite rule. take a look at apache manual .

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

修改: mod_rewrite的使用转义字符,所以如果你想使用UNI code字符,请使用它们重写规则,并保存的.htaccess 文件中UNI code!

Edit: mod_rewrite uses unescaped characters, so if you want to use unicode characters, use them in rewrite rule and save .htaccess file in unicode!