如果URL使用htaccess包含特定的字符串,则重定向 [英] redirect if url contains specific string using htaccess

查看:220
本文介绍了如果URL使用htaccess包含特定的字符串,则重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果URL包含论坛字符串,我想重定向到其他域, 83answers.com

I want to redirect to different domain, 83answers.com if url contains forum string.

就像我的网址是 test.guru99.com/forum/xyxyxzz 一样,它应该重定向到 83answers.com 。字符串论坛可以在URL中的任何位置。

Like if my url is test.guru99.com/forum/xyxyxzz then it should redirect to 83answers.com. String forum can be anywhere in the url.

我尝试关注

RewriteCond %{QUERY_STRING} forum
RewriteRule .* 83answers.com [R,L]

还有这个

RewriteCond %{REQUEST_URI} forum
RewriteRule .* 83answers.com

但是两者都没有用,请帮我解决这个问题。

But both didn't work ,Please help me to sort this out.

注意事项

推荐答案

对于基本URL,您不需要 RewriteCond ,只是 RewriteRule

For the base URL, you don't need RewriteCond, just 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]

组合规则:

RewriteRule forum http://83answers.com [R,L]

RewriteCond %{QUERY_STRING} forum
RewriteRule .? http://83answers.com [R,L]

请注意,您必须包括 http:// 。如果仅使用 83answers.com ,则服务器将尝试重定向到服务器上的URL。例如,它会将 http://test.guru99.com/forum/xyxyxzz 重定向到 http://test.guru99.com/83answers .com ,这不好。

Note that you must include http://. If you just use 83answers.com, the server tries to redirect to a URL on your server. For example, it would redirect http://test.guru99.com/forum/xyxyxzz to http://test.guru99.com/83answers.com, which is no good.

这篇关于如果URL使用htaccess包含特定的字符串,则重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆