Redirecting a URL
At
times, there is a need to redirect users to a new URL. There are many ways
to do this, the better way is doing it via the server or server side language
to produce a 301 (permanent redirect) response (more about these later).
After the examples, I have included a link to a text file or zipped text file -
depending on the browser, you might need to use the zipped (compressed) link and
unzip the file after download. Also keep in mind that a few of the
examples have been split into two lines to ensure the
code is seen. When in doubt, refer to the
examples.
ASP, .NET, PHP Permanent Redirect
If your web page is saved with a .asp, .net, or .php extension, you can rely
on some server side code to redirect the user to the new web page.
ASP 301 Redirect
For an ASP page, use this code:
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location",
"http://www.loudexpressions.com/sitemap.asp"
%>
Replace the location (http://www.loudexpressions.com/sitemap.asp) with the name of the new web page.
Text file
/
Zipped file
.NET 301 Redirect
If your web page
is
being processed in ASP.NET, you can use this code:
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location",
"http://www.loudexpressions.com/sitemap.asp");
}
</script>
Replace the location (http://www.loudexpressions.com/sitemap.asp) with the name of the new web page.
Text file
/
Zipped file
PHP 301 Redirect
If the web page has a .php extension (or another extension that is being
processed as php, like .phtml or .phtm - you will need to contact your hosting
provider if you have questions), you can use:
<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.loudexpressions.
Com/sitemap.asp" );
?>
Replace the location (http://www.loudexpressions.com/sitemap.asp) with the name of the new web page.
Text file
/
Zipped File
Other Server Side Permanent Redirect
There are some other server side languages like ColdFusion (.cfm), JavaServer
Pages (.jsp), using .htaccess, or IIS. You can also download the examples
above in a
zipped file
(and this also includes CFM / JSP and the example below).
Another Redirect Option
However, if you have
just relied on simple HTML for your website, or have no access to any of the
server side options, you might consider using a JavaScript and a meta tag to
redirect the users to the new page:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
<!-- Hide script from non-JS supported Browsers
function redirect(){
window.location.replace ("http://www.loudexpressions.com/
sitemap.asp");
}
setTimeout("redirect()",5000);
// end hiding
</script>
<meta http-equiv="Refresh" content="5; url=
http://www.loudexpressions.com/sitemap.asp">
<meta content="text/html; charset=utf-8" http-equiv=
"Content-Type">
<title>No Title</title>
</head>
<body>
You are being redirected to the new web page:
<a href="http://www.loudexpressions.com/sitemap.asp">
http://www.loudexpressions.com/sitemap.asp</a>
</body>
</html>
Replace the location (http://www.loudexpressions.com/sitemap.asp) with the name of the new web page
in
both places.
Text file
/
Zipped File
The JavaScript / Meta
Refresh tag should be used only as your last option to ensure your search engine
rankings are not affected.




Comments