.htaccess rewrite rule won't unicode character

2020-03-27 07:41发布

问题:

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

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

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.

回答1:

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]

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!