PDA

View Full Version : 301 redirects...


many_tentacles
06-25-2009, 10:33 AM
Hi

I have several URLs pointing to the same folder in IIS. However, I want to create 301 redirects so that no matter what URL is visited, you end up at the same site.

I have managed it with 302 redirects (see the code below) but this is not ideal from an SEO point of view. Is there any way of doing this with .net rather than having to create separate sites in IIS.

Thanks


<%@ Page Language="VB" Debug="true" %>

<script runat="server">

Dim strRemote As String

'***********************************************************
Sub Page_Load()
'***********************************************************
strRemote = Request.ServerVariables("HTTP_HOST")

Select Case strRemote
'- - - - - - - - - - - - - - - - - - -

Case "www.myurl1.co.uk"
Response.Redirect("http://www.myurl2.co.uk")
'- - - - - - - - - - - - - - - - - - -

Case "www.myurl2.co.uk"
Session("mysession") = "true"
'- - - - - - - - - - - - - - - - - - -

End Select

End Sub

</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>My Page</title>

</head>
<body>

<%= Session("mysession") %>

</body>
</html>

skids234
06-27-2009, 11:17 AM
Just set the http response headers manually like this:


Response.Clear();
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", "http://newurl.net/");
Response.End();

HostingASPNet
07-03-2009, 08:24 AM
Hello,

Other good solution is to use URL rewriting.

Regards

many_tentacles
07-08-2009, 01:41 PM
Thanks skids234, that did the job just as soon as I removed the semi-colons.

Response.Clear()
Response.Status = "301 Moved Permanently"
Response.AddHeader("Location", "http://newurl.net/")
Response.End()