Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我的Regex/htaccess语法正确吗?_Regex_.htaccess_Mod Rewrite - Fatal编程技术网

我的Regex/htaccess语法正确吗?

我的Regex/htaccess语法正确吗?,regex,.htaccess,mod-rewrite,Regex,.htaccess,Mod Rewrite,我最终决定深入研究正则表达式的奇妙世界 基本上我的目标是 浏览器发送: http://example.com/search/Bombay http://example.com/search/?city=Bombay Apache将其翻译为: http://example.com/search/Bombay http://example.com/search/?city=Bombay 我的规则是: RewriteRule ^search/([^/.]+)/?$ search/?city

我最终决定深入研究正则表达式的奇妙世界

基本上我的目标是

浏览器发送

http://example.com/search/Bombay
http://example.com/search/?city=Bombay 
Apache将其翻译为:

http://example.com/search/Bombay
http://example.com/search/?city=Bombay 
我的规则是:

RewriteRule ^search/([^/.]+)/?$ search/?city=$1
这是正确的方法吗?有什么好地方可以学习更多关于正则表达式的知识吗


提前感谢

您试图在该正则表达式中匹配太多内容。我会选择

RewriteRule ^search/([^/]+)/?$ search/?city=$1 [NC,L]
还请注意,我添加了
NC
不区分大小写标志和
L
最后一个标志,这意味着如果用户以混合或大写形式键入URL,则在匹配后它仍将匹配,它将停止访问htaccess文件并使用您当前匹配的内容

试着在这里了解他们,或者买一本像样的书


在这里发布之前,你真的应该尝试一下这些方法。

你测试过你当前的模式吗?它应该很好用。请确保启用mod_rewrite:
RewriteEngine on
Options+FollowSymLinks
。不要在最后像这样添加
[L,QSA]
标志:
RewriteRule^search/(^/]+)/?$search/?city=$1[L,NC,QSA]