[英]redirect if url contains specific string using htaccess
I want to redirect to different domain, 83answers.com
if url contains forum
string. 如果url包含
forum
字符串,我想重定向到不同的域, 83answers.com
。
Like if my url is test.guru99.com/forum/xyxyxzz
then it should redirect to 83answers.com
. 如果我的网址是
test.guru99.com/forum/xyxyxzz
那么它应该重定向到83answers.com
。 String forum can be anywhere in the url. 字符串论坛可以在网址的任何位置。
I have tried following 我试过以下
RewriteCond %{QUERY_STRING} forum
RewriteRule .* 83answers.com [R,L]
and also this 还有这个
RewriteCond %{REQUEST_URI} forum
RewriteRule .* 83answers.com
But both didn't work ,Please help me to sort this out. 但两者都没有用,请帮我解决这个问题。
Regards 问候
For the base URL, you don't need RewriteCond
, just RewriteRule
: 对于基本URL,您不需要
RewriteCond
,只需要RewriteRule
:
RewriteRule forum http://83answers.com [R,L]
For the query string, you were almost there: 对于查询字符串,您几乎就在那里:
RewriteCond %{QUERY_STRING} forum
RewriteRule .? http://83answers.com [R,L]
The combined rules: 合并规则:
RewriteRule forum http://83answers.com [R,L]
RewriteCond %{QUERY_STRING} forum
RewriteRule .? http://83answers.com [R,L]
Note that you must include http://
. 请注意,您必须包含
http://
。 If you just use 83answers.com
, the server tries to redirect to a URL on your server. 如果您只使用
83answers.com
,服务器会尝试重定向到您服务器上的URL。 For example, it would redirect http://test.guru99.com/forum/xyxyxzz
to http://test.guru99.com/83answers.com
, which is no good. 例如,它会将
http://test.guru99.com/forum/xyxyxzz
重定向到http://test.guru99.com/83answers.com
,这是不行的。
You can add an OR clause between two RewriteCond like this: 你可以在两个RewriteCond之间添加一个OR子句,如下所示:
RewriteCond %{QUERY_STRING} forum [OR]
RewriteCond %{REQUEST_URI} forum
RewriteRule ^ http://83answers.com/? [L,R=301]
Real answer that i maded code is 我编写代码的真实答案是
RewriteRule ^(.*)string(.*)$ http://your.website.com [R=301,L]
in place of string yoou can put your word 代替字符串你可以说出你的话
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.