How to redirect webpage from one domain to another?

ε祈祈猫儿з 提交于 2019-12-06 04:37:33

问题


How to redirect domain to another domain, when the first domain (webpage) load?


回答1:


A pure HTML alternative is the following <meta> tag in your HTML <head>:

<meta http-equiv="refresh" content="0;http://anotherdomain.com">

The 0 is here the amount of seconds the page has to stay open before redirecting. In this case, it'll happen immediately as soon as you loads the page. In contrary to the proposed JS solution, this will work fine as well in browsers with JS disabled.

However, if you've the ability to hook on server side code without trouble (i.e. response is not committed yet and so on), then I'd prefer that above the HTML/JS solution anyway.




回答2:


There are a couple of ways to do this. One is to add the an onload event to the body tag what sets window.location to the new domain.

<script language=javascript>
function redirect(){
  window.location = "http://example.com";
}
</script>

<body onload="redirect()">

</body>



回答3:


<% Response.Redirect ("http://example.com") %>

See here for further information.



来源:https://stackoverflow.com/questions/3450351/how-to-redirect-webpage-from-one-domain-to-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!