首先確定加載了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