Apache 配置301跳转

首先确定加载了mod_alias 模块

<Directory > 
..................
        Redirect permanent "^/abc.html$" "/"
        Redirect permanent "/ccc" "http://www.baidu.com"
</Directory> 

这样配置后当访问站点 /ccc目录时就会301跳转至百度 或是访问首页下的abc.html 文件时就会跳转至根目录

效果让下:

[root@bogon log]# curl  -I http://www.mqchina.org/ccc/
HTTP/1.1 301 Moved Permanently
Date: Tue, 25 Dec 2018 09:39:44 GMT
Server: Apache/2.2.15 (CentOS)
Location: http://www.baidu.com/
Connection: close
Content-Type: text/html; charset=iso-8859-1

注意:

permanent                   
                返回一个永久性重定向状态码(301),表示此资源的位置变动是永久性的。
temp
                    返回一个临时性重定向状态码(302),这是默认值。
seeother
                    返回一个“参见”状态码(303),表示此资源已经被替代。

参考官方说明:http://httpd.apache.org/docs/current/mod/mod_alias.html#redirect

猜你喜欢

转载自blog.51cto.com/1inux/2335183