.htaccess - 如何使用htaccess为整个网站设置维护模式

标签 .htaccess offline maintenance-mode

我发现 htaccess 的这段代码可以禁用整个网站(用于维护模式):

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !/offline.php$
RewriteRule .* /offline.php [R=307,L]

现在在我的 offline.php 页面中,我有一个指向 css 和 js 文件的链接,例如:

<link rel="stylesheet" href="include/css/error.css">
<script src="include/js/file.js"></script>

当我使用上面的代码设置维护模式时,加载了offline.php页面,但是没有css和js,我怎么允许加载这两个文件?

而且我认为为除我的 ip 之外的所有人禁用网站很有用,这样我就可以更新网站,这可能吗?

最佳答案

我找到了一个包含您问题答案的博客,请查看此 site

以下示例取自上述网站。

If you don’t already have an .htaccess file in the root of your domain, create one and add the following code. If you already have an .htaccess file, add the following code in front of everything that might be in there

RewriteEngine On

# Add all the IP addresses of people that are helping in development
# and need to be able to get past the maintenance mode.
# One might call this the 'allow people list'
RewriteCond %{REMOTE_HOST} !^83\.101\.79\.62
RewriteCond %{REMOTE_HOST} !^91\.181\.207\.191

# Make sure the maintenance mode only applies to this domain
# Example: I am hosting different sites on my server
# which could be affected by these rules.
RewriteCond %{HTTP_HOST} ^nocreativity.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.nocreativity.com$

# This is the 'ignore file list'. It allows access to all
# files that are needed to display the maintenance mode page.
# Example: pages, css files, js files, images, anything.
# IMPORTANT: If you don't do this properly, visitors will end up with
# endless redirect loops in their browser.
RewriteCond %{REQUEST_URI} !/offline\.htm$
RewriteCond %{REQUEST_URI} !/css\/style\.css$
RewriteCond %{REQUEST_URI} !/images\/logo\.png$

# Rewrite whatever request is coming in to the maintenance mode page
# The R=302 tells browsers (and search engines) that this
# redirect is only temporarily.
# L stops any other rules below this from executing whenever somebody is redirected.
RewriteRule \.*$ /offline.htm [R=302,L]

关于.htaccess - 如何使用htaccess为整个网站设置维护模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18801742/

相关文章:

apache - 如何阻止其他人的域名指向我的Apache托管网站?

php - 通过 htaccess 缩小动态 PHP 页面

Javascript 停止使用 HTML5 list 文件

web-applications - 如果缺少上下文,如何重定向到 "Maintenance Mode"页面

php - 现场维护中。如何重定向访问者?

.htaccess 捕获当前 url 并将 url 作为查询字符串到页面

apache - 将所有流量重定向到 https ://www. 目前我有两个版本 http://www 和 https://www

jquery - 可以在缓存 list 中包含外部文件吗?

离线网站

php - 如何在已经建立的网站上实现 "Maintenance Mode"