如何实现“维护模式"在已经建立的网站上 [英] How to implement "Maintenance Mode" on already established website
问题描述
我建立了一个超过 60 页的网站 (PHP).我现在才意识到(不幸的是)我应该内置维护模式"功能,以允许管理员暂时禁用网站并将其指向维护模式页面.这将只允许以管理员身份登录的用户查看网站.
I have built a website (PHP) with more than 60 pages. I have only now realized (unfortunately) that I should have built in an "In Maintenance Mode" feature to allow an admin to temporarily disable the website and point it to a Maintenance Mode page. This would only allow those logged in as an admin to view the website.
我看到的选项是:
在每个 PHP 页面的顶部添加一个新的包含"文件.
Add a new "include" file to the top of every single PHP page.
我有一个包含用于在
上显示导航栏每个页面(导航类).我可以编写维护模式
此类中的代码.
I have one include that is used to display the navigation bar on
every page (navigation class). I could write the Maintenance Mode
code in this class.
我还有其他选择吗?第一个选项似乎不是最有效的,而第二个选项似乎是糟糕的编程.有没有其他更好的方法可以在每个 php 文件中包含一个新文件?
Do I have any other options? The 1st option doesn't seem like the most efficient, and the 2nd one just seems like bad programming. Is there any other better way to include a new file on every single php file?
谢谢!
ps - 该网站尚未启动
ps - the site is not launched yet
推荐答案
您可以在维护模式下使用 .htaccess
重定向到另一个页面.
You can use .htaccess
to redirect to another page while on Maintenance Mode.
三个不同的例子:
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^11.111.111.111
RewriteCond %{REQUEST_URI} !^/maintenance.html$
RewriteRule ^(.*)$ http://domain.com/maintenance.html [R=307,L]
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.html$
RewriteCond %{REMOTE_HOST} !^888.888.888.888
RewriteRule $ /maintenance.html [R=302,L]
# redirect all visitors to alternate site but retain full access for you
ErrorDocument 403 http://www.alternate-site.com
Order deny,allow
Deny from all
Allow from 99.88.77.66
这篇关于如何实现“维护模式"在已经建立的网站上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!