显示更新页面一次

发布于 2024-09-14 03:38:05 字数 543 浏览 0 评论 0原文

我正在开发一个新网站,而我现有的网站仍在运行。我想要做的是当用户访问现有网站时将用户重定向到更新页面(无论他们进入哪个页面),然后将他们从该更新页面重定向到他们请求的原始页面。

我认为 mod_rewrite 规则看起来像这样

RewriteEngine On
# redirect to landing page
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1  // my real IP would go here
RewriteCond %{REQUEST_URI} !/UpdatePage.html$ [NC] // stop infinite loops on itself
RewriteRule .* /UpdatePage.html [R=302,L]

,上面的代码将实现将用户从任何页面重定向到更新页面。然而,显然这里的问题是它将导致连续循环......

我想我在这里需要某种形式的标志?我对 Mod_Rewrite 不太有经验,这样的事情可能吗?或者这可以在 Mod_Rewrite 之外使用纯 PHP 实现吗?

I am in the middle of developing a new website with my existing site still up and running. What I want to do is redirect the user to an update page when they visit the existing site (regardless of what page they enter on) then redirect them from that update page to the original page they requested.

I think the mod_rewrite rule would look something like

RewriteEngine On
# redirect to landing page
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1  // my real IP would go here
RewriteCond %{REQUEST_URI} !/UpdatePage.html$ [NC] // stop infinite loops on itself
RewriteRule .* /UpdatePage.html [R=302,L]

So the above would achieve redirecting the user from any page to the update page. However, evidently the issue here is it is going to cause a continuous loop...

I imagine I need some form of flag here? I am not really too experienced with Mod_Rewrite is something like this possible? Or is this something that can be achieved outside of Mod_Rewrite with pure PHP?

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

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

发布评论

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

评论(3

装迷糊 2024-09-21 03:38:06

由于当前站点的实现方式(一切都通过index.php页面),我能够简单地使用一些会话变量来检测用户是否应该重定向到更新页面,例如

<?php

if (!isset($_SESSION['ShowUpdatePage']) || $_SESSION['ShowUpdatePage'] == "true")
{
    $_SESSION['ShowUpdatePage'] = "false";
    header("Location: UpdatePage.html");
}

?>

这也意味着他们将每个会话只被重定向一次,这正是我所寻找的。

Due to the way the current site is implemented (everything goes through index.php page) I was able to simply use some session variables in order to detect whether the user should be redirected to the update page or not e.g.

<?php

if (!isset($_SESSION['ShowUpdatePage']) || $_SESSION['ShowUpdatePage'] == "true")
{
    $_SESSION['ShowUpdatePage'] = "false";
    header("Location: UpdatePage.html");
}

?>

This also means that they will only ever get redirected once per session which is exactly what I was looking for.

带上头具痛哭 2024-09-21 03:38:06

在我看来,这是最好的方法:

真实站点:www.example.org
旧站点:old.example.org
新网站:new.example.org

“新”。域需要提前到位。当您切换站点时,您可以将所有访问旧站点的人重定向到 new.example.org。有一段时间,您的用户将拥有“不正确”的域名。几天后,您可以重定向“新”。到“www”。

In my opinion this is the best way to go about it:

real site: www.example.org
old site: old.example.org
new site: new.example.org

The 'new.' domain needs to be in place well beforehand. When you cut over the site you can just redirect everybody hitting the old site to new.example.org. For a while your users will have the 'incorrect' domain. After a few days you can redirect "new." to "www.".

没︽人懂的悲伤 2024-09-21 03:38:05

编辑:我有机会使用我的 htaccess 文件,并且确实找到了我在下面附加的解决方案。长话短说,即使它看起来有效,我也不会使用它。

原文:

如果您已经通过添加 REDIRECT_STATUS 检查进行重定向,则可以尝试不进行重定向:

RewriteEngine On
# redirect to landing page
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1  // my real IP would go here

RewriteCond %{ENV:REDIRECT_STATUS} 200

RewriteCond %{REQUEST_URI} !/UpdatePage.html$ [NC] // stop infinite loops on itself
RewriteRule .* /UpdatePage.html [R=302,L]

据我了解,这意味着:如果远程地址是某个 IP 地址,则重定向到 UpdatePage.html 并且它之前没有被重定向过。

我无法检查这是否会导致所需的行为,但我确实从这个问题的答案中得到了这一点: 清除 URL 重定向循环

经过测试的解决方案:

我尝试了我的 WAMP 设置并得出了以下结论:

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1  // my real IP would go here
RewriteCond %{REQUEST_URI} !/UpdatePage.html$ [NC] // stop infinite loops on itself
RewriteCond %{REQUEST_URI} ^(.+)\.html$ [NC] // Only handle html pages
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^(.+)\.html$ [NC] //don't redirect if the referer is a page. Should actually include the domain as well
RewriteRule .* /UpdatePage.html [R=302,L]

第一次访问网站中的任何 html 页面时应重定向到 UpdatePage,然后用户将单击该页面上的链接,然后将转到原始页面。然后设置引用环境变量,您可以检查它是否有效,然后不重定向。

这不处理访问网站的根目录。用户必须直接加载 html 页面。

我更喜欢你的解决方案(@james)。将逻辑编码到主网关 PHP 页面的顶部更简单,并且更不易出错,但我想我会尝试使用 htaccess 找到一种方法:-)。请注意,我自己永远不会使用这个特定的 htaccess 方法。

Edit: I had a chance to play with my htaccess file and I did figure out a solution that I have appended below. Long story short though, I wouldn't use it even though it seems to work.

Original:

You can try not redirecting if you have already redirected by adding the REDIRECT_STATUS check:

RewriteEngine On
# redirect to landing page
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1  // my real IP would go here

RewriteCond %{ENV:REDIRECT_STATUS} 200

RewriteCond %{REQUEST_URI} !/UpdatePage.html$ [NC] // stop infinite loops on itself
RewriteRule .* /UpdatePage.html [R=302,L]

From what I understand this would mean: redirect to the UpdatePage.html if the remote address is a certain IP address and it has not been redirected before.

I'm unable to check whether this will result in the desired behaviour, but I did get this from the answer on this SO question: Clean URL Redirect Loop.

Tested solution:

I played around with my WAMP setup and came up with this:

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1  // my real IP would go here
RewriteCond %{REQUEST_URI} !/UpdatePage.html$ [NC] // stop infinite loops on itself
RewriteCond %{REQUEST_URI} ^(.+)\.html$ [NC] // Only handle html pages
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^(.+)\.html$ [NC] //don't redirect if the referer is a page. Should actually include the domain as well
RewriteRule .* /UpdatePage.html [R=302,L]

The first time to any html page in the site should redirect to the UpdatePage then the user would click a link on that page and will go to the original page. The referer environment variable is then set and you can check if it is valid and then not redirect.

This does not handle going to the root of the website. The user must be loading an html page directly.

I much prefer your solution (@james). Coding the logic into the top of the main gateway PHP page is simpler and far less error prone, but I figured I would try to find a way using htaccess :-). Please note that I would never use this particular htaccess method myself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文