框架到 htaccess 或 php 重定向

发布于 2024-10-04 19:42:37 字数 641 浏览 0 评论 0原文

我有一个指向我的主域名的域名,但他使用了一个框架(我无法更改这一点,我的主机只提供这种类型的重定向,甚至不允许我重定向到redirect.html)

<FRAME SRC="http://www.domain111.com/" NORESIZE>

我如何强制这个辅助域名重定向到我的主网站,没有框架? 到目前为止我尝试过:

RewriteCond %{HTTP_HOST} ^www.domain222.com$[OR]
RewriteCond %{HTTP_HOST} ^domain222.com$
RewriteRule ^(.*)$ http://www.domain111.com/$1 [R=301,L] 

但是

if (preg_match("/domain2222.com/i", $_SERVER['HTTP_REFERER'])) {
  header("HTTP/1.1 301 Moved Permanently");
  header("Location: http://www.domain111.com/");
  exit;
}

那是一个无限循环,因为重定向来自该框架

我应该做什么?更改主机不是一个选项

i have a domain pointing to my main, but hes using a frame (i cant change this, my host only provides this type of redirect and dont even allow me to redirect to a redirect.html)

<FRAME SRC="http://www.domain111.com/" NORESIZE>

how can i force this secondary domain to redirect to my main site, without frames?
so far i tried:

RewriteCond %{HTTP_HOST} ^www.domain222.com$[OR]
RewriteCond %{HTTP_HOST} ^domain222.com$
RewriteRule ^(.*)$ http://www.domain111.com/$1 [R=301,L] 

also

if (preg_match("/domain2222.com/i", $_SERVER['HTTP_REFERER'])) {
  header("HTTP/1.1 301 Moved Permanently");
  header("Location: http://www.domain111.com/");
  exit;
}

but thats a infinite loop since the redirect comes from that frame

what should i do? changing host is not a option

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

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

发布评论

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

评论(3

游魂 2024-10-11 19:42:37

这只能通过基于 Javascript 的 frame buster 实现。

原始版本:

<script type="text/javascript">
  if(top != self) top.location.replace("http://maindomain.com");
</script>

This is possible only with a Javascript-based frame buster.

A primitive version:

<script type="text/javascript">
  if(top != self) top.location.replace("http://maindomain.com");
</script>
早乙女 2024-10-11 19:42:37

@thejh:突破框架

<script type="text/javascript">
<!--
if (top.location != self.location) top.location = self.location;
// -->
</script>

@thejh: Break out of the frame?

<script type="text/javascript">
<!--
if (top.location != self.location) top.location = self.location;
// -->
</script>
玉环 2024-10-11 19:42:37

经过一天的尝试,我找到了无需 javascript 的解决方案!

它仅使用 htaccess,并将其放在指向框架的目录中:

  RewriteCond %{HTTP_REFERER} !^http://www\.ethicsoft\.it/(.*)$
  RewriteRule ^(.*) http://www.ethicsoft.it/$1 [R=301,NC]

它对我有用,但我建议使用浏览器和域提供商与框架的不同组合进行一些测试,因为它完全取决于传递的引用值到加框页面。

希望有帮助!

after trying for a day I found the solution without javascript!

It uses htaccess only, and I put it in the directory where I point my frame:

  RewriteCond %{HTTP_REFERER} !^http://www\.ethicsoft\.it/(.*)$
  RewriteRule ^(.*) http://www.ethicsoft.it/$1 [R=301,NC]

it worked for me, but I suggest to make some test with different combination of browsers and domain providers with frames, because it totally depends on the referer value passed to the framed page.

hoping is helpful!

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