2017年6月27日 星期二

Apache 停機小技巧 調整 404 not Found

在網站上線後,要顧慮的就很多啦
如果網站要停機進行調整,就要寫公告訊息

而網站連結眾多,怎麼在讓使用者連結時都會顯示停機公告呢?

我們可以在停機時,指向至一個空的網站即可
當使用者連線時,就會連不上原本的網頁
這時就會出現404 找不到網頁

因此就可以將404指向至公告頁即可
有兩種作法


1.調整Httpd.conf

ErrorDocument 404 /errors/not_found.html


2.如果有開mod_rewirte  可以設定在.htaccess


ErrorDocument 404 /pages/errors/404.php

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^/404/$
RewriteRule ^(.*)$ /pages/errors/404.php [L]



參考資料:

  • https://httpd.apache.org/docs/2.4/custom-error.html
  • https://stackoverflow.com/questions/19962787/rewrite-url-after-redirecting-404-error-htaccess

沒有留言:

張貼留言