【问题标题】:Synchronize cross-domain page address同步跨域页面地址
【发布时间】:2016-12-14 11:45:04
【问题描述】:

我有两个链接:

http://something.something.com/ (an local institute server...)
http://xxx.xxx.xxx.xxx/ (an amazon cloud C2)

我希望我的用户和几乎每个人都可以访问http://something.something.com/,但这个链接不是我想要配置的,我只有 FTP 访问它,我希望它静默地将访问者重定向到 http://xxx.xxx.xxx.xxx/

我已经研究和测试,使用 iframe,我没有得到链接翻译,例如,我没有得到例如 http://something.something.com/something/ 默默地翻译成 http://xxx.xxx.xxx.xxx/something/,在 iframe 上,它搜索 @987654326 @ 在本地服务器中插入,它不存在。并且导航 iframe 并没有反映本地主机地址

到目前为止,我所阅读的内容产生了一些想法,例如使用 postMessage.htaccess,但我对什么是最好的(甚至是有效的)解决方案感到困惑,因为我什至不确定我会在谷歌上搜索什么,真的很感谢你的指导。

update.1:

我对 FTP 的访问权限有限,它是一个共享域,所以我有一个 home/www/mydir 目录,我无权访问服务器 ROOT 目录或系统和服务配置。

【问题讨论】:

    标签: javascript .htaccess cross-browser cross-domain postmessage


    【解决方案1】:

    在本地网络上,您可以通过在每台本地 PC 上将 ip 注册到 /etc/hosts 来创建别名。

    xxx.xxx.xxx.xxx   someting.something.com
    

    【讨论】:

    • 我相信我说的不准确,实际上我访问权限有限,这个研究所存储了很多页面,他们通过 FTP 开放访问,给我一个home/www/myspace
    • 不,我的意思是如果你在本地电脑上应用它,你可以从本地浏览器访问http://something.something.com/something。但实际上你的请求会被发送到http://xxx.xxx.xxx.xxx/something,没有服务器配置变化
    • 哦,很有趣,但我需要它对任何从任何地方访问它的人都有效。但我不明白,这个问题是模棱两可的:)
    • 如果你想从任何地方(另一台电脑)访问,流程类似,但你需要在你的网络的 dns 中注册该 ip。
    • 这就是问题所在,我没有“要设置的 DNS 域”,我在服务器中有一个空间:http://something.something.com/ 我实际上想访问外部服务器 http://xxx.xxx.xxx.xxx/“静默"(仍然使用something.something.com地址)
    【解决方案2】:

    这比较棘手,但我已经解决了。更糟糕的是,我的local 地址不允许使用.htaccess 代理规则,所以我依赖iframepostMessage.htaccess

    在因缺少代理方式而苦苦挣扎之后,我配置了.htaccess,因此任何链接都会产生相同的地址,我的index.html 文件:

    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^/index.html$
    RewriteRule .* /index.html [L]
    

    local server,一个用户访问,我这样做了:

        <iframe id="subD" width="100%" height="100%" src="http://x.x.x.x">
            Sorry your browser did not support iframes.
        </iframe>
    
        <script>
            // load url on iframe  
            var sub = window.location.pathname;
            document.getElementById("subD").
                contentWindow.document.
                location.href="http://x.x.x.x" + window.location.pathname;
    
            //get url from amazon server
            window.addEventListener("message", updateUrl, false);
            function updateUrl (event) {
                var origin = event.origin || event.originalEvent.origin;
                if (origin !== "http://x.x.x.x")
                    return;
                current = window.location.pathname
    
                //take care of maintaining a back history whille navigating
                window.history.pushState({"link":current},"",event.data);
            }
    
            // on back/next event load history on frame
            window.onpopstate = function(e){
                if(e.state == e.state.link){
                    var rand = Math.floor((Math.random()*1000000)+1);
                    var iframe = document.getElementById('subD');
                    iframe.src = "http://x.x.x.x" + e.state.link + "?uid=" + rand;
                } else {
                    history.back();
                }
            };
        </script>
    

    amazon server我发送消息更新local server

      <script>
          parent.postMessage(window.location.pathname,"http://something.something")
      </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 2014-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-22
      • 2015-08-21
      相关资源
      最近更新 更多