[英]I need help with redirects
有一个页面有两个域:
www.exampleone.com
www.exampletwo.com
我需要重定向到起始页面:
www.exampleone.com
至www.exampleone.com/#!/news.html
www.exampletwo.com
到www.exampletwo.com/#!/news.html
最后但并非最不重要的是,对于每个页面我都需要这样的重定向,例如: www.exampleone.com/about.html
到www.exampleone.com/#!/about.html
www.exampletwo.com/about.html
到www.exampletwo.com/#!/about.html
我真的不知道如何解决这个问题,我应该使用Javascript还是.htaccess? 对于我的示例中的最后一次重定向,最好使用条件吗? 但怎么样?
有任何想法吗?
注意:内容是用ajax加载的,所以索引页面总是一样的,这就是/#!/...
的原因。
编辑:直截了当,有现场地址http://www.jester04.ch或http://www.jester04baden.ch ,初始重定向已解决,你可以在js文件中看到,但对于/#!/
重定向我还需要帮助,谢谢。
首先,我重定向两个主页:
RewriteCond %{REQUEST_URI} ^/$
RewriteRule (.*) /#!/news.html [R,L]
然后是所有其他页面
RewriteRule (.*) /#!/$1 [R,L]
没有测试,但这应该工作。
您可以将这个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;
}
应该管用:
redirect 301 / http://www.exampleone.com/#!/news.html
redirect 301 /about.html http://www.exampleone.com/#!/about.html
例如,对于exampletwo.com
将它放在根文件夹中的.htaccess文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.