开发者

I need help with redirects

There is a page with two domains:

www.exampleone.com

www.exampletwo.com

I need a redirect to the start page:

www.exampleone.com to www.exampleone.com/#!/news.html

www.exampletwo.com to www.exampletwo.com/#!/news.html

and last but not 开发者_JAVA百科least, for every page I need a redirect like this, e.g.: www.exampleone.com/about.html to www.exampleone.com/#!/about.html www.exampletwo.com/about.html to www.exampletwo.com/#!/about.html

I don't really know how to solve that, should I use Javascript or .htaccess? for the last redirect in my example, it's better to use conditions right? but how?

any ideas?

Note: The contents are loaded with ajax, so the index page is always the same, that why the /#!/... thing.

EDIT: straightforward, there are the live addresses http://www.jester04.ch or http://www.jester04baden.ch, the startpage redirect is solved as you can see in the js file, but for the /#!/ redirects I still need help, thank you.


First I'd redirect both the homepages:

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

Then all the other pages

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

Didn't test it but this should work.


You can put this block of JS code inside separate .js file then include this file in every page:

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;
}


Should work:

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

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

same for exampletwo.com

Put this in a .htaccess file in the root folder.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜