【问题标题】:Temporary redirect to maintenance page临时重定向到维护页面
【发布时间】:2011-12-07 13:41:26
【问题描述】:

我正在尝试编写一个规则来将所有 URL 重定向到一个临时页面,以便可以完成一些站点更新,但它最终会陷入无限循环。

  RewriteCond %{HTTP_HOST} ^(.*)mysite\.com$
  RewriteCond %{REQUEST_URI} !^(.*)temp$
  RewriteRule ^(.*)$ http://www.mysite.com/temp [R=307,L]

如何判断是不是临时页面?

【问题讨论】:

    标签: .htaccess mod-rewrite redirect apache2


    【解决方案1】:

    您需要为除维护文件之外的所有请求编写规则。

    .htaccess 应该是:

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

    【讨论】:

      【解决方案2】:

      我所做的是将所有流量重定向到非来自我的 IP 的 maintenance.html 页面。

      第一个重写条件避免了无限循环。

      RewriteCond %{REQUEST_URI} !/maintenance.html$ 
      RewriteCond %{REMOTE_ADDR} !^172\.16\.254\.1$
      RewriteRule $ /maintenance.html [R=302,L] 
      

      【讨论】:

        【解决方案3】:

        有效,我试过了。它将所有请求重定向到维护页面。

            <IfModule mod_rewrite.c>
         RewriteEngine on
         RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
         RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
         RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
         RewriteRule .* /maintenance.html [R=302,L]
        </IfModule>
        

        【讨论】:

          猜你喜欢
          • 2021-09-14
          • 2011-06-03
          • 2014-05-15
          • 1970-01-01
          • 2017-07-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多