Tuesday, January 20, 2009

Redirects (Html, ASP.Net, JSP, ...)

Html (not generally recommended)

<html>
<head>
<META HTTP-EQUIV="Refresh"CONTENT="0; URL=http://www.new-url.com">
</head>
<body>
This page is redirecting your browser to www.new-url.com<br>
Please, click <a href="http://www.new-url.com">here</a> if redirection doesn't work.
</body>
</html>
ASP.Net
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{   
   Response.Status = "301 Moved Permanently";
   Response.AddHeader("Location","http://www.new-url.com/");
}
</script>
JSP
<%
response.setStatus(301);
response.setHeader("Location", "http://www.new-url.com/" );
response.setHeader("Connection", "close" );
%>

No comments: