php - htaccess 中的自定义 503 页面为 "/path/to/index.php?maintenance"?

标签 php .htaccess mod-rewrite

我有一个移动网站,我将其与名片上的二维码结合使用。目前,当我将我的主要网站置于维护状态时,我使用 503 重定向到 maintenance.php。但这也排除了移动网站。我想要实现的是,在维护模式下仍然可以访问我的移动网站以及该目录 (/qr/) 中的所有文件和文件夹。此外,我想将访问者重定向到我的移动名片,并向他们显示一条消息,表明他们正在访问替代网站。

我的移动名片位于 mydomain.com/qr/。我在 <body> 之后添加了这个我的/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{}
?>

所以我希望我的 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需要使用别名,因此我有理由这样做。

我哪里做错了,我怎样才能达到我想要的结果?

干杯,

网络小 Sprite

最佳答案

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

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

关于php - htaccess 中的自定义 503 页面为 "/path/to/index.php?maintenance"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22136164/

相关文章:

php - 如何在 PHP 中更新其中包含空格的字段

php - 如何从日期范围 PHP 中获取年数

html - 确保万维网。或域名前的https

.htaccess - mod_rewrite 强制 www 前缀有选择地工作

apache - 如何停止 .htaccess 指令而不重写循环

php - 在 PHP MySQL 中将用户名传递给 url

php - 插入前检查 PostgreSQL 表

.htaccess - RewriteRule后如何在地址栏中保留原始jpg

apache - 如何创建 .htaccess 来显示 SVG?

apache - .htaccess代码阻止了我网站的所有访问量,怎么了?