apache 将域下的所有请求重定向到静态页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1314616/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 18:05:33  来源:igfitidea点击:

Redirect ALL requests under a domain to static page

apacheconfiguration.htaccessredirect

提问by barfoon

I am trying to redirect ALL requests for mydomain.com whether they are something like:

我正在尝试重定向对 mydomain.com 的所有请求,无论它们是这样的:

to be redirected to

被重定向到

As long as it has mydomain.com in it, they should see this page - its a we'll be back soon message.

只要其中包含 mydomain.com,他们就会看到此页面 - 这是我们很快就会回来的消息。

Should I do it in .htaccess or conf? How?

我应该在 .htaccess 还是 conf 中做?如何?

回答by barfoon

I actually ended up finding the answer on ServerFault:

我实际上最终在 ServerFault 上找到了答案:

https://serverfault.com/questions/32513/url-redirect-to-another-page-on-the-same-site

https://serverfault.com/questions/32513/url-redirect-to-another-page-on-the-same-site

"This example will 302 redirect all URLs to "/underconstruction.html":

“此示例将 302 将所有 URL 重定向到“/underconstruction.html”:

RewriteEngine On
RewriteCond %{REQUEST_URI} !=/underconstruction.html
RewriteRule ^ /underconstruction.html [R=302]

(which translates as "If URI is not /underconstruction.html, redirect to /underconstruction.html")" - Tommeh

(翻译为“如果 URI 不是 /underconstruction.html,则重定向到 /underconstruction.html”)”-Tommeh