apache - 将除一页以外的所有页面重定向到错误 503 自定义页面

标签 apache .htaccess mod-rewrite errordocument

用于 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(除了 www.domain.com/503.html 给我 200)。

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

最佳答案

您在第二个规则集中使用了两个 anchor 。就这么简单:

RewriteEngine on
RewriteBase /

ErrorDocument 503 /503.html

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

关于apache - 将除一页以外的所有页面重定向到错误 503 自定义页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32778357/

相关文章:

apache - Poodle漏洞需要将SSL 3.0改为TLS

php - PHP错误.htaccess限制文件夹深度

apache - .htaccess 文件的 RewriteRule 不起作用

.htaccess mod_rewrite 变量通过重定向

apache - 为 CloudFlare 用户强制使用 .htaccess 的 HTTPS 和非 WWW

php - Easyphp & SwiftMailer 4.3 无法发送消息 (PHP/SWIFT)

apache - 安装 www 和非 www ssl 证书 apache

java - FTP 客户端 listFiles() 在某些机器上工作

带有 ssl 和反向代理的 WordPress (nginx)

Apache 重写规则 - 防止重写的 URL 出现在浏览器 URL 栏中