首页 > 解决方案 > Apache 2.4 维护 html 页面图像未加载

问题描述

我正在尝试在 apache 2.4 中实现维护页面而无需重新启动和特定的 503 错误代码。我正在关注这个网站https://www.shellhacks.com/redirect-site-maintenance-page-apache-htaccess/

下面是我的 html 文件,图像文件maintenance.svg也在同一个根 htdocs 文件夹中:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body, html {
  height: 100%;
  margin: 0;
  /* The image used */
  background-image: url("maintenance.svg");
  /* Full height */
  height: 100%; 

  /* Center and scale the image nicely */
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}
</style>
</head>
<body>
</body>
</html>

重写规则如下:

DocumentRoot "${SRVROOT}/htdocs"
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteCond %{DOCUMENT_ROOT}/maintenance.enable -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /maintenance.html [L]
ErrorDocument 503 /maintenance.html

我不是 Apache 专家,需要您的帮助才能使用重写规则加载图像。

标签: mod-rewriteapache2.4maintenance-mode

解决方案


最后的 RewriteCond 是重写的异常。您可以添加另一个,它与以前的隐式与:

RewriteCond %{REQUEST_URI} !maintenance.svg

推荐阅读