URL重写时,如何匹配任何Unicode字符?

时间:2015-10-28 15:59:40

标签: regex .htaccess unicode url-rewriting

我有这个.htaccess.文件:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-zA-Z0-9]*)/?([a-zA-Z0-9]*)?/?([a-zA-Z0-9]*)?/?$ index.php?controller=$1&action=$2&id=$3 [NC,L]

此规则适用于a-z,A-Z和0-9,但我希望规则匹配任何Unicode字符。我试过了This

RewriteRule ^([A-Za-z0-9_-\s]+)/?([A-Za-z0-9_-\s]+)?/?([A-Za-z0-9_-\s]+)?/?$ index.php?controller=$1&action=$2&id=$3 [NC,L]

This

RewriteRule ^([\s\S]*)/?([\s\S]*)?/?([\s\S]*)?/?$ index.php?controller=$1&action=$2&id=$3 [NC,L]

但它似乎不起作用。我做错了什么?

1 个答案:

答案 0 :(得分:1)

您可以尝试:

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)/?([^/]*)?/?([^/]*)?/?$ index.php?controller=$1&action=$2&id=$3 [QSA,L]