0

我有两个网站(twigplay.com 和 mimuz.com)。我想将 twigplay.com 页面重定向到相应的 mimuz.com 页面。例如,如果用户导航到 twigplay.com/about.html,我希望他们被重定向到 mimuz.com/about.html。我希望这是动态的,因为我有超过 60,000 个 URL。我对如何做到这一点有一个想法,但我对javascript知之甚少。

我的想法:获取当前页面 uri > 保存到变量 > 重定向到 mimuz.com/page-uri

这可以用javascript吗?

4

3 回答 3

1

在网页中为所有 twigplay.com url 加载此 javascript:

$(document).ready(function() {
var pathname =$(location).attr('href');
var arr= pathname.split('/');
window.location = "mimuz.com/"+arr[arr.length-1];
});

但出于安全原因,我强烈建议您使用服务器端脚本语言(例如:php 等),因为这些带有 java 脚本的方法只是黑客攻击而不是完全证明。

于 2013-08-02T19:58:57.460 回答
0

var pathname = window.location.pathname;
window.location="http://mimuz.com"+路径名;

如果您使用 PHP,请将此代码放在页面顶部的 HTML 之前

<?php
$url= "http://mimuz.com/".basename($_SERVER['PHP_SELF']); /* Getting the current page */
header("Location: $url");
?>
于 2013-08-02T20:00:10.673 回答
0

有可能但可能不是进行重定向的理想场所。如果您将此 javascript 添加到 twigplay.com 上的所有页面,它将为您处理重定向:

<script type="text/javascript">
  (function(){
      // changes the location's hostname, the path remains the same
      // so if you're at http//twigplay.com/whatever/the/url.html it will
      // redirect to http://mimuz.com/whatever/the/url.html
      window.location.hostname = 'mimuz.com';
  })();
</script>

尽管发出 HTTP 301 来传达您已将内容移动到新域的事实,但在您的服务器上设置重定向可能更理想。如果您使用的是 Apache 网络服务器,您可能希望使用mod_rewrite来发出重定向。您将在.htaccess文件中放入的一组示例规则:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^twigplay\.com$
RewriteRule ^(.*)$ http://mimuz.com/$1 [L,R=301]

这实质上是告诉 Apache 重定向到twigplay.com的任何 url以重定向到相同的 url 但在mimuz.com并发出 HTTP 301 Moved Permanently 标头,这将通知搜索引擎他们拥有的有关原始 url 的任何信息都应该适用到新的。

于 2013-08-02T20:05:36.247 回答