.htaccess站点关闭以进行维护

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了.htaccess站点关闭以进行维护相关的知识,希望对你有一定的参考价值。

Site Down For Maintenance
  1. I recently needed to move one website from a shared web host to our internal server. After some discussion, we decided to simply add a "Site Down For Maintenance" page to the site to prevent users from submitting orders during the hosting change. Using the following .htaccess code snippet, we were able to send all users to a maintenance.html page no matter which page they requested:
  2.  
  3. RewriteEngine On
  4. RewriteBase /
  5. RewriteCond %{REQUEST_URI} !^maintenance.html$
  6. RewriteRule ^(.*)$ http://domain.com/maintenance.html [R=307,L]
  7.  
  8. ***
  9.  
  10. Once we posted the maintenance.html page and .htaccess code on both the old hosting environment AND new hosting environment, we switched the DNS settings. Before making the switch, we had ported the website's code to a "utility" domain and made adjustments so that the website would function well in the new hosting environment. Now that the DNS had been changed, we wanted to make sure that the website would function well on the new domain within the new hosting environment. Unfortunately the code above blocks EVERYONE from accessing any file besides the maintenance.html file. Fortunately my gifted IT team had the answer:
  11.  
  12. RewriteEngine On
  13. RewriteBase /
  14. RewriteCond %{REMOTE_ADDR} !^11.111.111.111
  15. RewriteCond %{REQUEST_URI} !^/maintenance.html$
  16. RewriteRule ^(.*)$ http://domain.com/maintenance.html [R=307,L]

以上是关于.htaccess站点关闭以进行维护的主要内容,如果未能解决你的问题,请参考以下文章

如何关闭 .NET 站点进行维护?

关闭 django 站点进行维护?

.htaccess使用URL中的#item重写站点以进行直接文件访问

Apache重写规则仅适用于新连接

最全最详细publiccms其他常用代码片段(内容站点)

使用 .htaccess 将子目录设置为根目录 [关闭]