mod_rewrite 所有内容到一个登陆页面

发布于 2024-09-19 17:59:32 字数 205 浏览 1 评论 0原文

我需要关闭整个网站,因此我想将所有请求路由到登陆页面。 mod_rewrite 是什么样的?我的指令在 Firefox 中给了我一个“永远无法完成”的错误。

RewriteEngine on
RewriteCond %{REQUEST_URI} !^[^.]*/$
RewriteRule ^(.*)$ /alert.php [R=301,L]

I need to take down an entire site, so I want to route everything request to a landing page. What does the mod_rewrite look like for that? My directives are giving me a "can never complete" error in firefox.

RewriteEngine on
RewriteCond %{REQUEST_URI} !^[^.]*/$
RewriteRule ^(.*)$ /alert.php [R=301,L]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

攒眉千度 2024-09-26 17:59:32

您重定向到的页面与重写模式匹配,因此当浏览器由于 301 重定向而尝试请求该页面时,它会再次重定向(导致无限循环,Firefox 足够聪明,可以注意到这一点)。您需要在规则中添加例外以避免这种情况:

# the conditions are implicitly combined
# with a logical AND
RewriteCond %{REQUEST_URI} !=/alert.php
RewriteCond %{REQUEST_URI} !^[^.]*/$
RewriteRule ^(.*)$ /alert.php [R=301,L]

The page you're redirecting to matches the rewrite pattern, so when the browser tries to request it as a result of the 301 redirect, it gets redirected again (causing an infinite loop, which Firefox is smart enough to notice). You'll want to add an exception to your rule to avoid this:

# the conditions are implicitly combined
# with a logical AND
RewriteCond %{REQUEST_URI} !=/alert.php
RewriteCond %{REQUEST_URI} !^[^.]*/$
RewriteRule ^(.*)$ /alert.php [R=301,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文