简体   繁体   English

在htaccess中访问“ /path/to/index.php?maintenance”的自定义503页面?

[英]Custom 503 page in htaccess to “/path/to/index.php?maintenance”?

I have a mobile website that I use in conjunction with QR codes on our business cards. 我有一个移动网站,可与我们名片上的QR码一起使用。 At the moment, when I put my main website in maintenance, I use a 503 redirect to maintenance.php. 目前,当我将主要网站进行维护时,我使用503重定向到maintenance.php。 But that also takes out the mobile website. 但是,那也拿走了移动网站。 What I would like to achieve is that my mobile website and all the files and folders within that directory (/qr/) are still accessible while in maintenance mode. 我想实现的是,在维护模式下,仍然可以访问我的移动网站以及该目录(/ qr /)中的所有文件和文件夹。 Additionally, I want to redirect visitors to my mobile business card and show them a message that they are visiting a substitute website. 此外,我想将访问者重定向到我的移动名片,并向他们显示一条消息,表明他们正在访问替代网站。

My mobile business card is located at mydomain.com/qr/. 我的移动名片位于mydomain.com/qr/。 I added this after the <body> tag of my /qr/index.php: 我在/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{}
?>

So I want my 503 error page to be mydomain.com/qr/?cp=xxxxx&maintenance (I need the cp for other things). 因此,我希望我的503错误页面为mydomain.com/qr/?cp=xxxxx&maintenance (我需要使用cp进行其他操作)。

Among one of the things I've tried, is that I've set the following as my .htaccess in the root folder: 我尝试过的其中一项操作是,在根文件夹中将以下内容设置为.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]

But I get returned a 500 Internal Server Error. 但是我返回了500 Internal Server Error。 I've read somewhere that /path/to/503.php needs to be in an alias, hence my reason to do that. 我读过某个地方/path/to/503.php需要使用别名,因此我这样做的原因是。

What am I doing wrong, and how can I achieve my desired result? 我做错了什么,如何才能达到预期的效果?

Cheers, 干杯,

Webgremlin Webgremlin

Using Jon's tip, I got my desired result by changing my htaccess to this: 使用乔恩的技巧,通过将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

I also had to add <base href="http://www.mydomain.com/qr/" /> to the head of my /qr/index.php file. 我还必须将<base href="http://www.mydomain.com/qr/" />到我的/qr/index.php文件的头部。 Otherwise it would try to load my css and images from mydomain.com/style.css and mydomain.com/images rather than from mydomain.com/qr/. 否则,它将尝试从mydomain.com/style.css和mydomain.com/images而不是从mydomain.com/qr/加载我的CSS和图像。

Hope this helps someone. 希望这对某人有帮助。

使用错误文档有什么问题?

ErrorDocument 503 /qr/index.php?cp=xxxxx&maintenance

You're getting the error because Alias command isn't allowed in .htaccess. 您收到错误消息是因为.htaccess中不允许使用Alias命令。 It can only be placed in Apache config like httpd.conf . 只能将其放在httpd.conf类的Apache配置httpd.conf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM