如何从特定类别重定向到另一个网站

时间:2015-03-30 14:12:44

标签: javascript .htaccess url redirect directory

请建议如何进行以下重定向:

  

www.siteA.com/ 目录 / keep-all-those-urls /→www.siteB.com/directory/keep-all-those-urls/

但同时重定向其他目录:

  

www.siteA.com/→www.siteA.com/ (此处无重定向)

2 个答案:

答案 0 :(得分:0)

您可以在/directory/.htaccess文件中使用此代码:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?siteA\.com$ [NC]
RewriteRule ^ www.siteB.com%{REQUEST_URI} [L,NE,R=302]

答案 1 :(得分:0)

function reDirection(){
  var currentDomain= location.host; // might be wwww.siteA.com
  var currentPath = location.pathname;
  var reDirectionUrl = "www.site2.com"; // www.site2.com
  var reDirectionUrl = (currentPath != "/")? reDirectionUrl+currentPath : currentDomain;
  window.location = "http://"+reDirectionUrl;

}