Regex utf-8 arabic

2019-09-08 05:04发布

i have 404 NOT FOUND when i have utf-8 (arabic) in my slug url

there is my code in php file:

'slug' => '[A-Za-z0-9\_-]+'

and this in htaccess file :

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

#Charset
AddDefaultCharset utf-8

#Protect - DOS
LimitRequestBody 10000000

#Index Protect
Options All -Indexes

<Files .htaccess>
order allow,deny
deny from all
</Files>

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

RewriteCond %{THE_REQUEST} ^[a-zA-Z0-9\-_]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]

when i have link like : www.test.com/تست server return 404 not found and when i use

'slug' => '[ا-یa-zA-Z0-9\-_]+'

and the same for htaccess i have loop redirection!

ا-یa-zآ-یA-Z

2条回答
淡お忘
2楼-- · 2019-09-08 05:48

You can use ([^/]+) , it works!
This pattern allows everything that is not a slash.

查看更多
三岁会撩人
3楼-- · 2019-09-08 05:49

Try changing the character class part of the regex to [\p{L}\p{N}\p{Pd}_]

\p{L} matches anything unicode that qualifies as a Letter but not underscores

\p{N} matches anything that looks like a number

\p{Pd} is Punctuation Dash which includes hyphen.

See here for more on Unicode Regular Expressions

查看更多
登录 后发表回答