[英]Custom 503 page in htaccess to “/path/to/index.php?maintenance”?
我有一个移动网站,可与我们名片上的QR码一起使用。 目前,当我将主要网站进行维护时,我使用503重定向到maintenance.php。 但是,那也拿走了移动网站。 我想实现的是,在维护模式下,仍然可以访问我的移动网站以及该目录(/ qr /)中的所有文件和文件夹。 此外,我想将访问者重定向到我的移动名片,并向他们显示一条消息,表明他们正在访问替代网站。
我的移动名片位于mydomain.com/qr/。 我在/qr/index.php的<body>
标记之后添加了此代码:
<?php if(isset($_GET["maintenance"])) {
header('HTTP/1.1 503 Service Temporarily Unavailable');
echo '<div class="maintenance">Our website is currently undergoing maintenance. You are now viewing our mobile business card as a substitute. Our apologies for any inconvenience, we will be back shortly.</div>';
}
else{}
?>
因此,我希望我的503错误页面为mydomain.com/qr/?cp=xxxxx&maintenance
(我需要使用cp
进行其他操作)。
我尝试过的其中一项操作是,在根文件夹中将以下内容设置为.htaccess:
RewriteEngine On
Alias /qr/index\.php "/qr/index.php?cp=xxxxx&maintenance"
RewriteCond %{REMOTE_ADDR} !^xxx\.xxx\.xxx\.xxx$
RewriteCond %{REQUEST_URI} !/qr/$
RewriteCond %{REQUEST_URI} !\.(css|png|vcf)$
RewriteRule .* /qr/index\.php [L]
但是我返回了500 Internal Server Error。 我读过某个地方/path/to/503.php
需要使用别名,因此我这样做的原因是。
我做错了什么,如何才能达到预期的效果?
干杯,
Webgremlin
使用乔恩的技巧,通过将htaccess更改为此,我得到了想要的结果:
#BEGIN 503 Maintenance
ErrorDocument 503 /qr/index.php?cp=xxxxx&maintenance
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^xxx\.xxx\.xxx\.xxx$
RewriteCond %{REQUEST_URI} !^/qr/.*$
RewriteRule .* - [R=503,L]
#EINDE 503 Maintenance
我还必须将<base href="http://www.mydomain.com/qr/" />
到我的/qr/index.php文件的头部。 否则,它将尝试从mydomain.com/style.css和mydomain.com/images而不是从mydomain.com/qr/加载我的CSS和图像。
希望这对某人有帮助。
使用错误文档有什么问题?
ErrorDocument 503 /qr/index.php?cp=xxxxx&maintenance
您收到错误消息是因为.htaccess中不允许使用Alias
命令。 只能将其放在httpd.conf
类的Apache配置httpd.conf
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.