【问题标题】:Redirect all but one page to error 503 custom page将除一页之外的所有页面重定向到错误 503 自定义页面
【发布时间】:2015-12-23 01:27:09
【问题描述】:

用于 apache 服务器的 htaccess 导致我所有的 IIS 服务器在维护时都将关闭。我需要将所有内容重定向到错误 503 自定义页面并返回 503 错误,但我不知道正确的解决方案。

RewriteEngine on
RewriteBase /

ErrorDocument 503 /503.html

RewriteRule ^.*$ - [L,NC,R=503]

这个结果变成这样:(响应不是我的自定义响应)

Service Unavailable

The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

再试一次:

RewriteEngine on
RewriteBase /

ErrorDocument 503 /503.html

RewriteRule ^(?!503.html)$ - [L,NC,R=503]

给我我需要的东西,但只为 www.domain.com 和所有其他页面给我 404(除了给我 200 的 www.domain.com/503.html)。

所以我需要将除 domain.com/503.html 之外的每个页面重定向到自定义 503 错误页面并返回错误代码。

【问题讨论】:

    标签: apache .htaccess mod-rewrite errordocument


    【解决方案1】:

    您在第二个规则集中使用了两个锚点。很简单:

    RewriteEngine on
    RewriteBase /
    
    ErrorDocument 503 /503.html
    
    RewriteRule ^(?!503.html).* - [R=503,L,NC]
    

    【讨论】:

    • 最后,一个适合我的解决方案。非常感谢。
    【解决方案2】:

    你可以使用否定:

    RewriteEngine on
    
    ErrorDocument 503 /503.html
    
    RewriteRule !^503\.html$ - [L,NC,R=503]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-04
      • 1970-01-01
      • 2011-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多