重定向所有子域名的主域名页面 [英] Redirect any sub domain to a page on main domain

查看:333
本文介绍了重定向所有子域名的主域名页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是一个quicky真的。我希望能够重定向任何人谁类型的一个 subdomain.mydomain.com 被重定向到一个网页上我的主要领域。即如果我输入: answers.mydomain.com 我会被重定向到 mydomain.com/suberror 例如

Just a quicky really. I want to be able to redirect anybody who types a subdomain.mydomain.com to be redirected to a page on my main domain. i.e If I typed: answers.mydomain.com I would be redirected to mydomain.com/suberror for instance.

我想这是可能的话一个普遍的规则,因为我认为这将是更容易添加语句排除,我不希望被重定向而不是增加语句包括所有其他子域的任何子域。我需要把这个使用的.htaccess 文件的方式。

I would like this to be a universal rule if possible because I thought it would be easier to add statements to exclude any subdomains that I didn't want to be redirected rather than add statements to include every other subdomain. I will need to this using a .htaccess file by the way.

请你能告诉我,如果这是可能的,如果是这样,怎么....在此先感谢!

Please could you tell me if this is possible, and if so, how.... Thanks in advance!

推荐答案

尝试在你的.htaccess文件添加以下内容到一个合适的位置:

Try adding this to an appropriate place in your .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^answers\.mydomain\.com$   [NC]
RewriteRule ^ http://mydomain.com/suberror  [L,R]

只要请求的主机是 answers.mydomain.com ,该规则将被应用。随着正则表达式匹配设置为 ^ 任何的URI将匹配和目标将被重定向到的 http://mydomain.com/suberror

As long as the requested host is answers.mydomain.com, the rule will be applied. With the regex match set to ^, any URI will match and the target will be redirected to http://mydomain.com/suberror

如果你想被重定向到/ suberror只有特定URI请求,你可以调整 ^ 适当的东西。

If you want only specific URI requests to be redirected to /suberror, you can tweak the ^ to something appropriate.

编辑:

对于所有的子域(包括www.mydomain.com):

For all subdomains (including www.mydomain.com):

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.mydomain\.com$   [NC]
RewriteRule ^ http://mydomain.com/suberror  [L,R]

要排除www.mydomain.com,在重写规则之前加入这一行:

To exclude www.mydomain.com, add this line before the RewriteRule:

RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$  [NC]

这篇关于重定向所有子域名的主域名页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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