我终于决定深入研究正则表达式的美妙世界。
基本上我的目标是
浏览器发送:
http://example.com/search/Bombay
Apache 翻译成这样:
http://example.com/search/?city=Bombay
我的规则尝试是这样的:
RewriteRule ^search/([^/.]+)/?$ search/?city=$1
这是正确的方法吗?有什么好的地方可以了解更多关于 Regex 的信息吗?
提前致谢
我终于决定深入研究正则表达式的美妙世界。
基本上我的目标是
浏览器发送:
http://example.com/search/Bombay
Apache 翻译成这样:
http://example.com/search/?city=Bombay
我的规则尝试是这样的:
RewriteRule ^search/([^/.]+)/?$ search/?city=$1
这是正确的方法吗?有什么好的地方可以了解更多关于 Regex 的信息吗?
提前致谢
You are trying to match too much in that regex. I would go for
RewriteRule ^search/([^/]+)/?$ search/?city=$1 [NC,L]
Also notice that I have added the NC
non-case-sensitive flag and the L
last flag this means if a user types in the URL in mixed or upper case then it will still match also once it matches it will stop accessing the htaccess file and go with what you have currently matched.
Try to learn about them here http://www.regular-expressions.info/ or get a decent book.
Also really you should try these things before posting here.