apache 404\403錯誤頁面跳轉

1、全局下使用404跳轉

在httpd.conf下配置跳轉

vim /usr/local/httpd/conf/httpd.conf
<Directory "/usr/local/httpd-2.4.25/htdocs">
    AllowOverride None
    Require all granted
    ErrorDocument 404 /aa.jpg  #配置跳轉頁面,注意aa文件必須在htdocs根目錄下
    ErrorDocument 403 /abc.jpg #403跳轉
</Directory>

#檢查配置重新加載配置

apachectl -t
Syntax OK
apachectl graceful

#測試跳轉,在沒有主頁文件時會跳轉到403錯誤,顯示403錯誤頁面。在找不到文件或頁面路徑時會跳轉到404錯誤,並顯示404錯誤頁面內容。

 

2、在虛擬主機中使用403,404跳轉頁面

pwd
/usr/local/httpd/conf/extra
vim httpd-vhosts.conf
<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/var/html/www"
    ServerName www.zhang.com
    ServerAlias zhang.com
    ErrorLog "logs/www-error_log"
    CustomLog "logs/www-access_log" common
    ErrorDocument 404 /404.html
    ErrorDocument 403 /403.html
    
</VirtualHost>

#錯誤頁面必須放到DocumentRoot對應的根目錄下

ls /var/html/www/
403.html  404.html   index.html.ht

#檢查配置加載

apachectl -t

Syntax OK

apachectl graceful

#測試錯誤頁面跳轉成功,此處注意如果錯誤頁面文件小於512個字節的時候,在IE瀏覽器下錯誤頁面將不起作用,修復方法:

ErrorDocument 404 http://****/403.html
ErrorDocument 403 http://****/404.html

轉自:apache 404\403錯誤頁面跳轉

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章