htaccess: RewriteRule, Tomcat & 503



给定以下htaccess:

DirectoryIndex
RewriteEngine on
RewriteCond %{HTTPS} !on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L,QSA]
RewriteRule ^ http://%{HTTP_HOST}:8080%{REQUEST_URI} [P]    

如果Tomcat实例在端口8080下运行,请求将被传递。如果实例没有运行,我将得到一个难看的503错误。

我试图用一个定制的页面来替换它。如此:

ErrorDocument 503 "offline"

但这不是:

ErrorDocument 503 /home/www-data/error/503.html

我:

Additionally, a 503 Service Unavailable error was encountered while trying to use an ErrorDocument to handle the request.

正确的解决方案是什么?

对于ErrorDocument,您需要给出html页面相对于文档根目录的路径。因此,如果DocumentRoot是/home/www-data/,只需设置/error/503.html

现在,如果这是/home/www-data/中存在的.htaccess,那么作为该目录子目录的所有文档都将应用该规则。所以我认为即使你的/error/503.html是由你的代理指令处理:

RewriteRule ^ http://%{HTTP_HOST}:8080%{REQUEST_URI} [P]

应该改成:

RewriteCond %{ENV:REDIRECT_STATUS} !=503
RewriteRule ^ http://%{HTTP_HOST}:8080%{REQUEST_URI} [P]

我认为应该足够了,或者你可以从匹配路径中排除/error

最新更新