【问题标题】:Get the sub url load it into a new url获取子 url 将其加载到新的 url
【发布时间】:2016-01-16 06:14:15
【问题描述】:

假设有人使用此网址访问我的网站:

mywebsite.com/somethingsomething123

我想创建一个新的 url 并把它变成这样:

anotherwebsite.com/somethingsomething123

我怎样才能做到这一点?
任何帮助将不胜感激。

【问题讨论】:

  • 尝试使用location.pathname;例如,var path = location.pathname; var newurl = "anotherwebsite.com" + path;

标签: javascript url url-rewriting


【解决方案1】:

所以,使用 Javascript 你是这样的:

var path_Name; // it will be like somethingsomething123
redirect_Url="www.example.com"; // anotherdomain.com
 function test(){ 
 path_Name = window.location.pathname;
window.location.href='http://'+redirect_Url+path_Name
};
<button onClick="test()" >Click Here </button>
<h3>I have used test() function on click event you can use it on window.onLoad or any other javascript event </h3>

注意:如果您想使用 url 重写,请指定是否 它的 windows 或 linux 主机

【讨论】:

  • 老实说,我的网址看起来像 mywebsite.com/qwerty=ok&hello=somethingsomething123,其他网站也是如此
  • 我不是在寻找重定向
猜你喜欢
  • 1970-01-01
  • 2010-12-11
  • 1970-01-01
  • 2018-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-23
相关资源
最近更新 更多