I have a mobile website that I use in conjunction with QR codes on our business cards. At the moment, when I put my main website in maintenance, I use a 503 redirect to 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. 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/. I added this after the <body>
tag of my /qr/index.php:
<?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).
Among one of the things I've tried, is that I've set the following as my .htaccess in the root folder:
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. I've read somewhere that /path/to/503.php
needs to be in an alias, hence my reason to do that.
What am I doing wrong, and how can I achieve my desired result?
Cheers,
Webgremlin
Using Jon's tip, I got my desired result by changing my htaccess to this:
#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. 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/.
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. It can only be placed in Apache config like httpd.conf
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.