我需要帮助重定向

时间:2010-12-12 21:25:29

标签: javascript .htaccess redirect dns

有一个页面有两个域:
www.exampleone.com
www.exampletwo.com

我需要重定向到开始页面:
www.exampleone.comwww.exampleone.com/#!/news.html
www.exampletwo.comwww.exampletwo.com/#!/news.html

最后但并非最不重要的是,每个页面我需要这样的重定向,例如:www.exampleone.com/about.htmlwww.exampleone.com/#!/about.html www.exampletwo.com/about.htmlwww.exampletwo.com/#!/about.html

我真的不知道如何解决这个问题,我应该使用Javascript还是.htaccess?对于我的示例中的最后一次重定向,最好使用条件吗?但是如何?

任何想法?

注意:内容是用ajax加载的,所以索引页面始终是相同的,这就是/#!/...的原因。

编辑:直截了当,有实时地址http://www.jester04.chhttp://www.jester04baden.ch,首页重定向已解决,正如您在js文件中看到的那样,但对于/#!/重定向,我仍然需要求助,谢谢。

3 个答案:

答案 0 :(得分:3)

首先,我会重定向两个主页:

RewriteCond %{REQUEST_URI} ^/$
RewriteRule (.*) /#!/news.html [R,L]

然后是所有其他页面

RewriteRule (.*) /#!/$1 [R,L]

没有测试,但这应该有用。

答案 1 :(得分:2)

您可以将此JS代码块放在单独的.js文件中,然后在每个页面中包含此文件:

var sURL = (window.location.href + "").replace("http://", "");
if (sURL.indexOf("/#!/") < 0) {
   if (sURL.substr(sURL.length - 1, 1) == "/")
       sURL = sURL.substr(0, sURL.length - 1);
   var arrTemp = sURL.split("/");
   var sDomain = arrTemp[0];
   var sPage = (arrTemp.length > 1) ? arrTemp[arrTemp.length - 1] : "news.html";
   var sNewUrl = sDomain + "/#!/";
   for (var i = 1; i < arrTemp.length - 1; i++)
      sNewUrl += arrTemp[i] + "/";
   sNewUrl += sPage;
   window.location.href = "http://" + sNewUrl;
}

答案 2 :(得分:0)

应该工作:

redirect 301 / http://www.exampleone.com/#!/news.html

redirect 301 /about.html http://www.exampleone.com/#!/about.html

同样适用于exampletwo.com

将它放在根文件夹中的.htaccess文件中。