重定向所有的通配符子域的根域 [英] redirect all wildcard subdomains to root domain
问题描述
好吧,我已经做搜索了相当多的,但仍然无法找到足够的具体处理我的问题什么的。
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屋!