【问题标题】:how to set maintenance mode for entire website with htaccess如何使用 htaccess 为整个网站设置维护模式
【发布时间】:2013-09-19 01:14:52
【问题描述】:

我找到了 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 之外的所有人的网站很有用,这样我可以更新网站,这可能吗?

【问题讨论】:

    标签: .htaccess offline maintenance


    【解决方案1】:

    如果您的根目录中还没有 .htaccess 文件 域,创建一个并添加以下代码。如果你已经有一个 .htaccess 文件,在所有内容前面添加以下代码 可能在里面

    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]
    

    【讨论】:

    • 您的链接是 404。不确定这是不是玩笑
    • @Jon 我在答案中添加了相同的网站内容。请检查。并感谢您的更新。
    【解决方案2】:

    Step1:在根目录下创建一个文件'.maintence',如.htaccess

    Step2:将这段代码放入文件中

      <?php $upgrading = time();?>
    

    Step3:保存文件,然后你可以看到默认的维护信息'Briefifiable for scheduled maintenance。请稍后再查看。'。

    如果您想拥有自己的警告消息,请执行以下操作:

    创建一个“maintenance.php”文件并将其放置在您的 wp-content 目录中,wordpress 使用此文件在您设置的任何强制维护期间显示。

    【讨论】:

      【解决方案3】:

      这是一个很好的答案,但这是其中的代码,以防链接失效:

      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]
      

      【讨论】:

        猜你喜欢
        • 2017-05-16
        • 2018-09-18
        • 1970-01-01
        • 2016-01-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多