Web redirection allows a domain to point to another domain or to a specific URL within a domain.
The most common situations in which you will need to set up a redirect are the following:
- You have moved your website to a new address and want your visitors to go directly to the new site (so you do not lose visits).
- You have a new subdomain and want to redirect its requests to a specific subdirectory of your domain.
- You want to automatically provide access via a secure protocol.
To redirect one page to another using code, you need to implement one of the following examples in your page's index file, depending on the programming language you are using.
In this post, we show you how to set up a web redirect using the programming languages PHP, HTML, ASP and ASP.NET.
-
PHP redirection
File: index.php
<?php
Header( “HTTP/1.1 301 Moved Permanently” );
Header( “Location: http://www.nueva_URL.com” );
php?> -
HTML redirection
File: index.html
<html>
<head>
<meta http-equiv="refresh" content="0; url=http://www.nueva_URL.com">
</head>
<body>
</body>
</html> -
Classic ASP redirection
File: index.asp
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.nueva_URL.com/"
%> -
ASP .NET redirection
File index.net
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.nueva_URL.com");
}
</script>