如何使用htaccess为整个网站设置维护模式 [英] how to set maintenance mode for entire website with htaccess

查看:100
本文介绍了如何使用htaccess为整个网站设置维护模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经找到htaccess的代码来禁用整个网站(用于维护模式):

i have found this code for htaccess to disable the entire website (for maintenance mode):

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

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

Now in my offline.php page i have a link to css and js files, like:

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

当我使用上述代码设置维护模式时,将加载offline.php页面,但没有CSS和js,我如何允许加载这两个文件?

when i use the code above to set the maintenance mode, the offline.php page is loaded, but without the css and js, how can i allow the loading of these 2 files?

我认为这对除我的IP以外的所有人禁用该网站很有用,这样我就可以更新该网站,这可能吗?

and i think that is useful to disable the website for everyone except my ip, in this way i can update the website, is that possibile?

推荐答案

我找到了一个博客,其中包含您的问题的答案,请检查此网站

i find out an blog that contains answer for your question please check this site

以下示例摘自上述经血部位.

The below examples are taken from the above mentoined site.

如果您的根目录中还没有.htaccess文件, 域,创建一个并添加以下代码.如果您已经有 .htaccess文件,将以下代码添加到所有 可能在那里

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为整个网站设置维护模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆