将所有通配符子域重定向到根域 [英] redirect all wildcard subdomains to root domain

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

问题描述

好的,我已经进行了大量搜索,但仍然找不到足够具体的内容来解决我的问题.

Okay, I have done a fair amount of searching but still can't find something specific enough to handle my problem.

现在我有一个 DNS 记录,可以将所有其他子域重定向到我的服务器.我要问的是什么会使 example.mydomain.com 返回 HTTP/1.1 301 并重定向到 mydomain.com

Right now I have a DNS record that redirects all other subdomains to my server. What I'm asking is what would make example.mydomain.com return HTTP/1.1 301 and redirect to just mydomain.com

如果这已经被覆盖,我很抱歉,我找不到任何足够具体的东西.

My apologies if this has been covered, I just couldn't find anything specific enough.

推荐答案

使用 RewriteCond 来匹配除 mydomain.com 和 301 重定向之外的域:

Use a RewriteCond to match domains other than mydomain.com and 301 redirect them:

RewriteEngine On
# If the domain (any domain) is not exactly mydomain.com...
RewriteCond %{HTTP_HOST} !^mydomain\.com$ [NC]
RewriteRule (.*) http://mydomain.com/$1 [L,R=301,QSA]

您还可以更具体地查找 mydomain.com 的子域.上面的将匹配任何其他域.

You can also look more specifically for subdomains of mydomain.com. The one above would match any other domain.

# Match only subdomains of mydomain.com
RewriteCond %{HTTP_HOST} ^(.+)\.mydomain\.com$ [NC]
RewriteRule (.*) http://mydomain.com/$1 [L,R=301,QSA]

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

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