【问题标题】:htaccess: how to redirect all pages to a holding pagehtaccess:如何将所有页面重定向到保留页面
【发布时间】:2010-03-02 09:08:24
【问题描述】:

在我们安装第二台服务器时,我必须关闭一个站点大约半小时。使用 .htaccess,我如何将任何请求重定向到 domain.comdomain.com/holding_page.php

【问题讨论】:

    标签: .htaccess


    【解决方案1】:
    Options +FollowSymlinks
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !/holding_page.php$ 
    
    RewriteRule $ /holding_page.php$l [R=307,L]
    

    使用 307(感谢 Piskvor!)而不是 302 - 307 means

    请求的资源驻留 暂时在不同的 URI 下。 由于重定向可能会改变 有时,客户应该 继续使用 Request-URI 未来的请求。

    【讨论】:

    • 这似乎在 RewriteCond %{REQUEST_URI} !/indexTEMP.php$ RewriteRule $ /indexTEMP.php [R=307,L] 上工作 RewriteEngine
    • 由于这个答案仍然在搜索结果中排在首位,添加RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC] 可能是个好主意。这会阻止图像突破,将它们重定向到保留页面。我知道这严格来说不是原始问题的一部分 - 但仍然很方便。
    【解决方案2】:

    当我遇到这个问题时,这是我使用的解决方案(cmets 中的简要说明):

    RewriteEngine On
    RewriteBase /
    
    # do not redirect when using your IP if necessary
    # edit to match your IP
    RewriteCond %{REMOTE_ADDR} !^1\.1\.1\.1
    
    # do not redirect certain file types if necessary
    # edit to match the file types needed
    RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|css)
    
    # this holding page that will be shown while offline
    RewriteCond %{REQUEST_URI} !^/offline\.html$
    
    # use 503 redirect code during the maintenance job
    RewriteRule ^(.*)$ /offline.html [R=503,L]
    ErrorDocument 503 /offline.html
    
    # bots should retry accessing your page after x seconds
    # edit to match your maintenance window
    Header always set Retry-After "3600"
    
    # disable caching
    Header Set Cache-Control "max-age=0, no-cache, no-store"
    

    除了附加条件和标头之外,主要思想是在进行维护工作时使用503 状态代码

    503 代码代表Service Unavailable,在维护期间正是如此。使用它也将是 SEO 友好的,因为机器人不会索引 503 页面,它们将在指定的 Retry-After 之后返回以查找实际内容。

    在此处阅读更多详细信息:

    【讨论】:

      【解决方案3】:

      这样效果更好...

      Options +FollowSymlinks
      RewriteEngine on
      RewriteCond %{REQUEST_URI} !/holding_page.php$ 
      RewriteRule $ /holding_page.php [R=307,L]
      

      【讨论】:

        猜你喜欢
        • 2015-03-19
        • 2016-07-20
        • 1970-01-01
        • 1970-01-01
        • 2021-03-05
        • 2012-10-29
        • 2016-11-08
        • 2010-12-29
        相关资源
        最近更新 更多