.htaccess 重定向_.htaccess“关闭维护”页面重定向

.htaccess 重定向

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:

最近,我需要将一个网站从共享的虚拟主机迁移到我们的内部服务器。 经过一番讨论,我们决定只在站点上添加“维护站点”页面,以防止用户在更改主机期间提交订单。 使用以下.htaccess代码段,无论他们请求哪个页面,我们都可以将所有用户发送到maintenance.html页面:


RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ http://domain.com/maintenance.html [R=307,L]


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:

在旧的托管环境和新的托管环境上发布了maintenance.html页面和.htaccess代码后,我们便切换了DNS设置。 在进行切换之前,我们已将网站的代码移植到“实用程序”域中并进行了调整,以使网站在新的托管环境中能够正常运行。 现在已经更改了DNS,我们希望确保该网站在新的托管环境中的新域上能够正常运行。 不幸的是,以上代码阻止了每个人访问除maintenance.html文件之外的任何文件。 幸运的是,我有才华的IT团队得到了答案:


RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^11\.111\.111\.111
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ http://domain.com/maintenance.html [R=307,L]


The above code sends all users to maintenance.html EXCEPT those with the specified IP, which just so happened to be us. We got to test the website while others were locked out. When we were satisfied with the website, we removed the .htaccess code and the site was back up immediately!

上面的代码将所有用户发送到maintenance.html,除了具有指定IP的用户(恰好是我们)。 我们必须测试网站,而其他人则被锁定。 当我们对网站感到满意时,我们删除了.htaccess代码,并立即备份了该网站!

翻译自: https://davidwalsh.name/htaccess-maintenance-page-redirect

.htaccess 重定向

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值