2014-03-03 18 views
0

我有一個手機網站,我與我們的名片上的QR碼一起使用。目前,當我將我的主要網站進行維護時,我使用503重定向到maintenance.php。但是,這也拿出了手機網站。我想實現的是,在維護模式下,我的移動網站和該目錄中的所有文件和文件夾(/ qr /)仍然可以訪問。此外,我想將訪問者重定向到我的移動名片,並向他們顯示他們正在訪問替代網站的消息。htaccess中的自定義503頁面爲「/path/to/index.php?maintenance」?

我的移動名片位於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內部服務器錯誤。我讀過/path/to/503.php需要在別名中,因此我的理由是這樣做。

我在做什麼錯,我該如何達到我想要的結果?

乾杯,

Webgremlin

回答

2

使用錯誤文檔有什麼問題?

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

謝謝。我不知道爲什麼我沒有嘗試過,完美地工作。我必須在我的索引文檔的''標籤中設置'',以使圖像和CSS工作。我想我的index.php中的if語句中不再需要'header'了? – WebGremlin

1

你得到的錯誤,因爲Alias命令不能在.htaccess不允許的。它只能放置在Apache配置中,如httpd.conf

2

使用Jon的文章中,我得到了我想要的結果,通過改變我的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加載我的css和圖像,而不是從mydomain.com/qr/加載。

希望這可以幫助別人。