apache添加域名及301跳转的例子

发布时间:2019-09-03编辑:脚本学堂
apache添加域名及301跳转的例子

1、添加域名解析,用别名来做。
vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
 

复制代码 代码如下:
<VirtualHost *:80>
    ServerAdmin liuyi@315zhaopin.com
    DocumentRoot "/data/home/www/www"
    ServerName  123zp.com
    Serveralias www.315zhaopin.com
    ServerAlias www.123zhaopin.com
    ServerAlias www.123zp.cn
    ServerAlias www.123zp.com
    ServerAlias www.123zp.com
    ServerAlias 123zhaopin.cn
    ServerAlias 123zhaopin.com
    ServerAlias www.123zhaopin.cn
    ServerAlias xn--123-yh6Fq51K.com
    ServerAlias www.xn--123-yh6Fq51K.com
    ServerAlias xn--123-yh6F996JckB.com
    ServerAlias www.xn--123-yh6F996JckB.com
    ServerAlias xn--123-yh6fq51K.xn--fiqs8s
    ServerAlias www.xn--123-yh6fq51K.xn--fiqs8s
    ServerAlias xn--123-yh6F996JckB.xn--fiQs8S
    ServerAlias www.xn--123-yh6F996JckB.xn--fiQs8S
    ServerAlias 123rencai.com
    ServerAlias www.123rencai.com
    ServerAlias 123zp.com
    ServerAlias www.123zp.com
    ServerAlias 123zp.cn
    ServerAlias www.123zp.cn
    ErrorLog "logs/www.123zp.com-error_log"
    CustomLog "logs/www.123zp.com-access_log" common
</VirtualHost>

添加一条: ServerAlias www.123rencai.com
保存退出。

2、做301跳转,修改.htaccess文件。
vim /data/home/www/www/.htaccess
 

复制代码 代码如下:

RewriteEngine On
RewriteBase /
# Rewrite规则
RewriteRule ^index.htm$ index.php
RewriteRule ^jobs/jobs-show-([0-9]+).htm$ jobs/jobs-show.php?id=$1
RewriteRule ^company/company-show-([0-9]+).htm$ company/company-show.php?id=$1
RewriteRule ^resume/resume-show-([0-9]+).htm$ resume/resume-show.php?id=$1
RewriteRule ^news/news-list-([0-9]+)-([0-9]+).htm$ news/news-list.php?id=$1&page=$2
RewriteRule ^news/news-show-([0-9]+).htm$ news/news-show.php?id=$1
RewriteRule ^explain/explain-show-([0-9]+).htm$ explain/explain-show.php?id=$1
RewriteRule ^notice/notice-list-([0-9]+)-([0-9]+).htm$ notice/notice-list.php?id=$1&page=$2
RewriteRule ^notice/notice-show-([0-9]+).htm$ notice/notice-show.php?id=$1
RewriteEngine on
RewriteCond %{http_host} ^123zp.com [NC]
RewriteRule ^(.*)$ http://www.123zp.com/$1 [L,R=301]
RewriteCond %{http_host} ^123zhaopin.com [NC]
RewriteRule ^(.*)$ http://www.123zp.com/$1 [L,R=301]
RewriteCond %{http_host} ^123zhaopin.cn [NC]
RewriteRule ^(.*)$ http://www.123zp.com/$1 [L,R=301]
RewriteCond %{http_host} ^www.123zhaopin.cn [NC]

RewriteCond %{http_host} ^www.123rencai.com [NC]
RewriteRule ^(.*)$ http://123zp.com/$1 [L,R=301]
RewriteCond %{http_host} ^www.123zp.com [NC]
RewriteRule ^(.*)$ http://123zp.com/$1 [L,R=301]
RewriteCond %{http_host} ^123zp.cn [NC]
RewriteRule ^(.*)$ http://123zp.com/$1 [L,R=301]
RewriteCond %{http_host} ^www.123zp.cn [NC]
RewriteRule ^(.*)$ http://123zp.com/$1 [L,R=301]
RewriteCond %{http_host} ^xn--315-yh6Fq51K.com [NC]
RewriteRule ^(.*)$ http://123zp.com/$1 [L,R=301]
RewriteCond %{http_host} ^www.315zhaopin.com [NC]
RewriteRule ^(.*)$ http://123zp.com/$1 [L,R=301]
RewriteCond %{http_host} ^315zhaopin.com [NC]
RewriteRule ^(.*)$ http://123zp.com/$1 [L,R=301]
RewriteCond %{http_host} ^xn--315-yh6Fq51K.xn--fiQs8S [NC]
RewriteRule ^(.*)$ http://123zp.com/$1 [L,R=301]
RewriteCond %{http_host} ^www.xn--315-yh6Fq51K.xn--fiQs8S [NC]
RewriteRule ^(.*)$ http://123zp.com/$1 [L,R=301]
RewriteCond %{http_host} ^www.xn--315-yh6Fq51K.com [NC]
RewriteRule ^(.*)$ http://123zp.com/$1 [L,R=301]

添加一条 :
RewriteCond %{http_host} ^www.xn--315-yh6Fq51K.com [NC] :需要跳转的域名
RewriteRule ^(.*)$ http://123zp.com/$1 [L,R=301]        :主域名
保存退出
/etc/init.d/apachectl restart
重启服务器