如何从一个URL重定向到另一个URL

How to redirect from one URL to another URL?

本文关键字:URL 一个 重定向 另一个      更新时间:2023-09-26

如何使用JavaScript重定向到网页中的另一个URL?

window.location.href = "URL2"

在页面上的JS块内或包含的文件中;这是假设你真的想在客户端上完成。通常,服务器通过300系列响应发送重定向。

由于您用javascripthtml标记了问题。。。

对于纯HTML解决方案,可以在header中使用meta标记来"刷新"页面,指定不同的URL:

<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com/somepage.html">

如果您可以/想要使用JavaScript,您可以设置window:的location.href

<script type="text/javascript">
    window.location.href = "http://www.yourdomain.com/somepage.html";
</script>

您可以通过javascript重定向任何或多个URL,只需简单的window.location.hrefif else

使用此代码,

<script>
if(window.location.href == 'old_url')
{
    window.location.href="new_url";
}

//Another url redirect
if(window.location.href == 'old_url2')
{
    window.location.href="new_url2";
}
</script>

您可以通过此过程重定向许多URL。谢谢

如果要重定向,只需使用window.location即可。像这样:

window.location = "http://www.redirectedsite.com"

为什么选择javascript?

http://www.instant-web-site-tools.com/html-redirect.html

<html>
<meta http-equiv="REFRESH" content="0;url=http://www.URL2.com"> 
</html>

除非我理解错误。。。

location.href = "Pagename.html";

您还可以使用元标记重定向到另一个url。

<meta http-equiv="refresh" content="2;url=http://webdesign.about.com/">

http://webdesign.about.com/od/metataglibraries/a/aa080300a.htm