Javascript 通过查询url参数实现从html到aspx页面的url重定向

Javascript 通过查询url参数实现从html到aspx页面的url重定向,javascript,asp.net,html,url-redirection,Javascript,Asp.net,Html,Url Redirection,这将是一个漫长的过程 我有一个要求,我必须在我的旧网页中使用url重定向(基本上是一个完整的静态html页面) 我的要求是每次都将用户从静态html页面重定向到.aspx页面 i、 e如果发现我以前的页面位于 然后我必须重定向到下一页(.aspx) 目前我在html页面中使用javascript i、 e 我的downloadsite.htm页面标题中的脚本 现在问题来了 如何查询多个URL参数 i、 e。 当URL请求类似于 http://web.vatsag.com/app/en/dow

这将是一个漫长的过程

我有一个要求,我必须在我的旧网页中使用url重定向(基本上是一个完整的静态html页面)

我的要求是每次都将用户从静态html页面重定向到.aspx页面

i、 e如果发现我以前的页面位于

然后我必须重定向到下一页(.aspx)

目前我在html页面中使用javascript

i、 e

我的downloadsite.htm页面标题中的脚本

现在问题来了

如何查询多个URL参数

i、 e。 当URL请求类似于

http://web.vatsag.com/app/en/downloadsite.htm?lang=de&vers=1.10
我应该被重定向到具有相同URL参数的aspx页面

http://web.vatsag.com/app/newdownloadsite.aspx?lang=de&vers=1.10
我有一个javascript代码段,它返回url参数

function getQueryStringArray(){
    var assoc=[]; 
    var items = window.location.search.substring(1).split('&'); 
    for(var j = 0; j < items.length; j++) { 
       var a = items[j].split('='); assoc[a[0]] = a[1]; 
    }
    return assoc;
}
函数getQueryStringArray(){ var assoc=[]; var items=window.location.search.substring(1).split('&'); 对于(var j=0;j 如何使用此代码段获取所有URL参数以最终重定向到ASPX网页

非常感谢你的帮助


VATSAG

我想这段代码会帮你找到你想要的URL

// Original URL
var url = window.location.href; 
var newUrl = "";

// Split the String to get the Query strings
var splitString = url.split('?');


if (splitString.length > 1)
{
   // New Url With Query strings
   newUrl = "http://web.vatsag.com/app/newdownloadsite.aspx" + "?" + splitString[1];
}
else
{
   // New Url With NO query string
   newUrl = "http://web.vatsag.com/app/newdownloadsite.aspx"
}

通过在旧页面上使用一个简单的元标记,可以很容易地完成任务,该标记可以重定向到新页面

将以下行添加到旧静态html页面的标题部分:

<meta http-equiv="Refresh" content="0;URL=new_page_url" />

window.location不是字符串,而是结构/类。它有自己的成员变量。当您分配
location=“something”
时,您将分配给href成员。您可以查看它的其他成员

另外,另一个注意事项是:指定整个地址,如
http://web.vatsag.com/app/newdownloadsite.aspx
不推荐使用。相反,请使用
。/newdownloadsite.aspx
。这将有助于您将来重新定位站点

要回答您的问题,请尝试:

  location=location.pathname.replace(/en\/downloadsite.htm$/,"newdownloadsite.aspx") + location.search + location.hash;
  //Host name, protocol, port number is taken from current one. (Making it more portable)
  //By using pathname.replace, you ensure that if the directory path depth of the original html page on server is changed, still it would be portable.

顺便说一句,答案是MVCKarl-
.split(“?”[1]
)-应该也可以代替
location.search+location.hash

你有没有想过直接路由到.aspx页面而不是重定向?Scott Guthrie有一篇博文:在我看来,使用服务器进行上面建议的url重写更好。您不必将javascript放入所有遗留页面,客户端也不必首先加载遗留页面。如果他想在querystring中查询url参数,这将不起作用。谢谢。。。这真的很简单:)
  location=location.pathname.replace(/en\/downloadsite.htm$/,"newdownloadsite.aspx") + location.search + location.hash;
  //Host name, protocol, port number is taken from current one. (Making it more portable)
  //By using pathname.replace, you ensure that if the directory path depth of the original html page on server is changed, still it would be portable.