Apache重定向使用%{QUERY

编程入门 行业动态 更新时间:2024-10-28 11:30:25
Apache重定向使用%{QUERY_STRING}来匹配任何字符串(Apache Redirect Using %{QUERY_STRING} To Match A String Anywhere)

我想使用%{QUERY_STRING}进行Apache重定向,但它根本无法正常工作。

我想重定向任何网页中包含字符串的网页查询。 例如:

http://www.domain.com/328kadf83/dkad83kd/test83283/

该字符串将是“test”,如上所示。

我尝试过这个,但它似乎没有起作用:

RewriteEngine On RewriteCond %{QUERY_STRING} test RewriteRule (.*) http://www.other_domain.com/page.html [R=301,L]

在这种情况下我做错了什么? 主要的是 - 重定向需要匹配字符串“test”出现的URL中的任何位置 - 然后它将重定向到特定的网页。

我在这里看到的其他问题专门用于目录或页面名称后带变量的目录。

谢谢!

I'm looking to do an Apache redirect using %{QUERY_STRING} but it simply isn't working.

I am wanting to redirect any web page query that has a string anywhere in the URL. So for example:

http://www.domain.com/328kadf83/dkad83kd/test83283/

The string would be "test" as shown above.

I tried this, but it doesn't seem to be working:

RewriteEngine On RewriteCond %{QUERY_STRING} test RewriteRule (.*) http://www.other_domain.com/page.html [R=301,L]

What I am doing wrong in this case? The main thing is - the redirect needs to match anywhere in the URL where the string "test" appears - and it will then redirect to a specific web page.

The other questions I've seen on here are specifically for a directory or those with variables after a page name.

Thank you!

最满意答案

应该是这样的:

RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} /test [NC] RewriteRule .* http://www.other_domain.com/page.html [R=301,L]

Should be something like this:

RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} /test [NC] RewriteRule .* http://www.other_domain.com/page.html [R=301,L]

更多推荐

本文发布于:2023-07-28 01:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1298204.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   Apache   QUERY

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!