正则表达式在测试程序中有效,但在 .htaccess 中无效

发布于 2024-09-28 09:55:53 字数 338 浏览 1 评论 0原文

的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

少年亿悲伤 2024-10-05 09:55:53

您不需要转义斜线,而是转义点。并且 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 ??

暮色兮凉城 2024-10-05 09:55:53

<罢工>
^accommodation/destination.php\?code=([0-9]+)&destination=([^/]+)$

在我的服务器上测试,应该可以工作。

不,不,它永远不应该起作用。所以这里有一些可行的方法:

RewriteCond %{QUERY_STRING} ^code=([0-9]+)&destination=([^/]+)$
RewriteRule ^accomodation/destination\.php$ your.php [L]


^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:

RewriteCond %{QUERY_STRING} ^code=([0-9]+)&destination=([^/]+)$
RewriteRule ^accomodation/destination\.php$ your.php [L]
聚集的泪 2024-10-05 09:55:53

完成了,在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文