码迷,mamicode.com
首页 > 其他好文 > 详细

LAMP构架-域名跳转

时间:2018-03-04 14:44:12      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:lamp   域名跳转   

域名跳转

将之前使用的域名转向新域名,例如起点小说网最早使用的是www.cmfu.com,现在改成www.qidian.com;
由于老用户的存在只记住了www.cmfu.com,现在想输入老域名cmfu直接跳转到qidian.com上;

修改httpd-vhosts.conf配置文件

vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>
    DocumentRoot "/data/wwwroot/szl.com"
    ServerName szl.com
    ServerAlias www.example.com www.szl.com
    <IfModule mod_rewrite.c>                                        //需要mod_rewrite模块支持
      RewriteEngine on                                                    //打开rewrite功能
      RewriteCond %{HTTP_HOST} !^szl.com$                  //定义rewrite的条件,如果主机名(域名)不是szl.com,那就满足条件
      RewriteRule ^/(.*)$ http://szl.com/$1 [R=301,L]        //定义rewrite规则,满足上面的条件,那么这条就生效
    </IfModule>
    ErrorLog "logs/szl.com-error_log"
    CustomLog "logs/szl.com-access_log" common
</VirtualHost>

生效配置

/usr/local/apache2.4/bin/apachectl -t
/usr/local/apache2.4/bin/apachectl graceful

查询rewrite是否加载

/usr/local/apache2.4/bin/apachectl -M |grep rewrite

加载rewrite模块

vim /usr/local/apache2.4/conf/httpd.conf

取消注释LoadModule rewrite_module modules/mod_rewrite.so

再次生效配置

/usr/local/apache2.4/bin/apachectl -t
/usr/local/apache2.4/bin/apachectl graceful

测试

使用IE浏览器测试,否则其他浏览器有可能在szl.com前面自动添加www

www.example.com/admin.php 成功跳转为http://szl.com/admin.php

服务器测试:

[root@shu-test ~]# curl -x192.168.188.2:80 www.example.com/admin.php -I
HTTP/1.1 301 Moved Permanently
Date: Fri, 02 Mar 2018 10:10:25 GMT
Server: Apache/2.4.29 (Unix) PHP/5.6.30
Location: http://szl.com/admin.php
Content-Type: text/html; charset=iso-8859-1
[root@shu-test ~]#

访问www.example.com 无论后缀的文件目录有多少一样跳转到szl.com下

[root@shu-test ~]# curl -x192.168.188.2:80 www.example.com/1dfkdsjldfj/ldsjfaos/sdlfs.php -I
HTTP/1.1 301 Moved Permanently
Date: Fri, 02 Mar 2018 10:11:39 GMT
Server: Apache/2.4.29 (Unix) PHP/5.6.30
Location: http://szl.com/1dfkdsjldfj/ldsjfaos/sdlfs.php
Content-Type: text/html; charset=iso-8859-1
[root@shu-test ~]#

访问szl.com,不存在的文件目录错误将显示404

[root@shu-test ~]# curl -x192.168.188.2:80 szl.com/1dfkdsjldfj/lds -I
HTTP/1.1 404 Not Found
Date: Fri, 02 Mar 2018 10:13:54 GMT
Server: Apache/2.4.29 (Unix) PHP/5.6.30
Content-Type: text/html; charset=iso-8859-1
[root@shu-test ~]#

访问szl.com,存在的文件目录错误将显示200

[root@shu-test ~]# curl -x192.168.188.2:80 szl.com/admin.php -I
HTTP/1.1 200 OK
Date: Fri, 02 Mar 2018 10:15:26 GMT
Server: Apache/2.4.29 (Unix) PHP/5.6.30
X-Powered-By: PHP/5.6.30
Content-Type: text/html; charset=UTF-8
[root@shu-test ~]#

LAMP构架-域名跳转

标签:lamp   域名跳转   

原文地址:http://blog.51cto.com/shuzonglu/2082188

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!