我使用htaccess文件重定向搜索查询。
RewriteRule ^search/([a-zA-Z0-9\-\s]+)$ search.php?q=$1 [L,NC]
这适用于英文字母和空格。
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.
我也需要这个与这个角色一起工作:“+şöççüŞÖÇĞĞ”
有什么建议吗?
答案 0 :(得分:0)
您无法创建一个范围来覆盖unicode字符,但您可以将正则表达式更改为更宽松:
RewriteRule ^search/([^/_.]+)$ search.php?q=$1 [L,NC]
或者,如果您需要指定范围,您可以执行以下操作:
RewriteCond %{THE_REQUEST} \ /+search/(%[89A-F][0-9A-Z]|[A-Z0-9+-]|%20)+ [NC]
RewriteRule ^search/([^/_.]+)$ search.php?q=$1 [L]