正则表达式在测试程序中有效,但在 .htaccess 中无效
的 URL
'accommodation/destination.php?code=108459&destination=Yang+Chum+Noi'
我正在尝试重定向看起来像我正在使用的正则表达式
(^accommodation/destination\.php\?code=([0-9]+)&destination=([^/]+)$)
: ...在我的正则表达式测试器中工作正常,但当我在 .htaccess
文件中使用它时,它不起作用。
我在这里错过了什么吗?
I'm trying to redirect a URL that looks like
'accommodation/destination.php?code=108459&destination=Yang+Chum+Noi'
The regex I'm using:
(^accommodation/destination\.php\?code=([0-9]+)&destination=([^/]+)$)
...works fine in my regex tester but when I use it in the .htaccess
file it doesn't work.
Am I missing something here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不需要转义斜线,而是转义点。并且 RewriteRule 不关心询问点之后的字符,因此您必须使用 QSA 标志。
但是这个重定向看起来很奇怪,你如何在 htaccess 中使用这个正则表达式?
You don't need to escape slashes but the point. And RewriteRule don't care about caracters after interrogation point, so you have to use QSA flag.
But this redirection seems weird, how do you use this regexp in your htaccess ??
<罢工>
^accommodation/destination.php\?code=([0-9]+)&destination=([^/]+)$
在我的服务器上测试,应该可以工作。
不,不,它永远不应该起作用。所以这里有一些可行的方法:
^accommodation/destination.php\?code=([0-9]+)&destination=([^/]+)$
Tested on my server, it should work.No, no, it should never work. So here is something that will work though:
完成了,在 MatTheCat 和 bazmegakapa 的帮助下,我让它工作起来,在我修复了自己的拼写错误后,并使用此处的解决方案删除了 QSA 标志后,{QUERY_STRING} 解决方案就正常了 http://www.google.com/support/forum/p/Webmasters/thread?tid =55432a1ab73cdf5a&hl=en 现在可以使用了,再次感谢你们的帮助。
Done, with the help of both MatTheCat and bazmegakapa I got it to work, the {QUERY_STRING} solution was OK after I fixed my own typo, and after removing the QSA flag using the solution here http://www.google.com/support/forum/p/Webmasters/thread?tid=55432a1ab73cdf5a&hl=en it is now working, thanks again to both of you for your help.