将任何子域重定向到主域上的页面

编程入门 行业动态 更新时间:2024-10-23 03:24:41
本文介绍了将任何子域重定向到主域上的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

真的很快.我希望能够将任何键入 subdomain.mydomain 的人重定向到我的主域上的页面.例如,如果我输入:answers.mydomain,我将被重定向到 mydomain/suberror.

Just a quicky really. I want to be able to redirect anybody who types a subdomain.mydomain to be redirected to a page on my main domain. i.e If I typed: answers.mydomain I would be redirected to mydomain/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.

推荐答案

尝试将其添加到 .htaccess 文件中的适当位置:

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

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

只要请求的主机是 answers.mydomain,就会应用该规则.将正则表达式匹配设置为 ^,any URI 将匹配并且目标将被重定向到 mydomain/suberror

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

如果您只想将特定的 URI 请求重定向到/suberror,您可以将 ^ 调整为适当的内容.

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

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

For all subdomains (including www.mydomain):

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

要排除 www.mydomain,请在 RewriteRule 之前添加以下行:

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

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

更多推荐

将任何子域重定向到主域上的页面

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

发布评论

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

>www.elefans.com

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