簡體   English   中英

在htaccess中訪問“ /path/to/index.php?maintenance”的自定義503頁面?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM