导读域名怎么跳转到另一个域名?域名跳转到另一个域名,可以通过301重定向方式来实现。不同服务器,不同环境和语言,方法有所不同,我们这里简单介绍两种方式。很多企业,会申请多个域名,比如com、cn、net、

域名怎么跳转到另一个域名?域名跳转到另一个域名,可以通过301重定向方式来实现。不同服务器,不同环境和语言,方法有所不同,我们这里简单介绍两种方式。

很多企业,会申请多个域名,比如com、cn、net、info等,以此来保护企业品牌。这时如果想每个域名在访问时,均自动跳转到com上,要怎样实现呢?

域名准备:web1.com、web2.cn、web3.net、web4.info

1、Apache服务器

首先将域名解析到服务器IP:1.1.1.1

接着在http.conf中添加:

# set .net to .com
<VirtualHost 1.1.1.1>
ServerName web3.net
ServerAlias www.web3.net
RedirectMatch Permanent ^/(.*) http://web1.com/$1
</VirtualHost>
# set .cn to .com
<VirtualHost 1.1.1.1>
ServerName web2.cn
ServerAlias www.web2.cn
RedirectMatch Permanent ^/(.*) http://web1.com/$1
</VirtualHost>
# set .info to .com
<VirtualHost 1.1.1.1>
ServerName web4.info
ServerAlias www.web4.info
RedirectMatch Permanent ^/(.*) http://web1.com/$1
</VirtualHost>
<VirtualHost 1.1.1.1>
ServerAdmin xxxx@web1.com
ServerName web1.com
ServerAlias www.web1.com
</VirtualHost>

然后重启Apache服务器

2、.htaccess方式

在虚拟主机中,有Linux、Windows等操作系统,我们以比较普遍的Linux为例,使用.htaccess文件实现301重定向:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^web2.cn [NC,OR]
RewriteCond %{HTTP_HOST} ^web3.net [NC,OR]
RewriteCond %{HTTP_HOST} ^web4.info [NC,OR]
RewriteCond %{HTTP_HOST} ^web1.com$ [NC]
RewriteRule ^(.*)$ http://www.web1.com/$1 [L,R=301]
</IfModule>

这里,无论是cn、net还是info,均自动跳转至web1,而且web1.com也将自动跳转到www.web1.com。

以上是关于“域名怎么跳转到另一个域名”的介绍,如需注册域名,推荐旺隆创业网:http://www.dlwanglong.cn/services/domain/