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

编程入门 行业动态 更新时间:2024-10-25 02:22:02
本文介绍了如何使用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$ [OR] RewriteCond %{HTTP_HOST} ^www.nocreativity$ # 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为整个网站设置维护模式

本文发布于:2023-11-02 08:28:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551896.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   模式   网站   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!