简体   繁体   中英

htaccess RewriteRule to Turkish Characters

I use htaccess file to redirect search queries.

RewriteRule ^search/([a-zA-Z0-9\-\s]+)$ search.php?q=$1 [L,NC]

This works well for English letters and spaces.

http://localhost:8080/search/stack%20over%20flow   OK
http://localhost:8080/search/stack-over-flow   OK
http://localhost:8080/search/stack+over+flow    FAIL
http://localhost:8080/search/%C5%9Ftack%C3%B6verfl%C3%B6w   (ştaköverflöw) FAIL

The requested URL /search/ştacköverflöw was not found on this server.

http://localhost:8080/search/%C3%B6z%20%C5%9Fan   (öz şan)  FAIL

The requested URL /search/öz şan was not found on this server.

I need this to work with this characters too: "+ ş ö ç ğ ü Ş Ö Ç Ğ Ü"

Any suggestions?

You can't create a range to cover unicode characters, but you could change the regex to be a bit more lax:

RewriteRule ^search/([^/_.]+)$ search.php?q=$1 [L,NC]

Or, if you need to specify ranges, you may be able to do something like:

RewriteCond %{THE_REQUEST} \ /+search/(%[89A-F][0-9A-Z]|[A-Z0-9+-]|%20)+ [NC]
RewriteRule ^search/([^/_.]+)$ search.php?q=$1 [L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM