Mod rewrite, need to allow only letters, numbers and white spaces

房东的猫 提交于 2019-12-12 01:48:58

问题


Since I need to allow my users, to search strings with white spaces, I need to modify this rewrite rule (lighttpd engine).

"^/(results)/(query)/([0-9a-zA-Z_]+)$" => "index.php?action=results&query=$3",

To allow only letters, numbers and white spaces (I guess only those are needed to search some data from MySQL?).

Thank you in advance.


回答1:


Whitespace in regex is \s

"^/(results)/(query)/([0-9a-zA-Z_\s]+)$" => "index.php?action=results&query=$3"

or

"^/(results)/(query)/([\w\d\s_]+)$" => "index.php?action=results&query=$3"

If - sign needed, it must be the first in range

"^/(results)/(query)/([-0-9a-zA-Z_\s]+)$" => "index.php?action=results&query=$3"

See the basics on lighttpd wiki and complete regex reference.



来源:https://stackoverflow.com/questions/7375474/mod-rewrite-need-to-allow-only-letters-numbers-and-white-spaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!