Forum Moderators: open

Message Too Old, No Replies

Redirecting 301 on Microsoft-IIS/6.0

Redirecting 301 on Microsoft-IIS/6.0

         

ramachandra

7:04 am on Jun 16, 2005 (gmt 0)

10+ Year Member



My domain is hosted on Microsoft-IIS/6.0, what method I have follow to make 301 redirect from non-www to www.mydomain.com

Whether .htaccess file can be created for Windows server or I have to contact my web hosting server to do a permanent redirect.

Thanks

tedster

3:46 am on Jul 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See this thread:

[webmasterworld.com...]

mrMister

4:03 pm on Jul 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In ASP.Net, add this function to your page...

<script language="vb" runat="Server">
Sub redirect301(whereTo As String)
Response.Status = "301 Moved Permanently"
Response.Addheader("Location", whereTo)
Response.End
End Sub
</script>

in Classic ASP, add this function to your page...

<script language="vbscript" runat="Server">
Sub redirect301(whereTo)
Response.Status = "301 Moved Permanently"
Response.Addheader "Location", whereTo
Response.End
End Sub
</script>

Then in the same way as you'd use this code for a 302...

Response.redirect("http://www.microsoft.com/")

Use this code for a 301...

redirect301("http://www.microsoft.com/")

ramachandra

5:55 am on Jul 6, 2005 (gmt 0)

10+ Year Member



Hello mrMister

I have used this ASP Code, it worked for my site.

<%
PathInfo = Request.ServerVariables("PATH_INFO")
ServerName = Request.ServerVariables("SERVER_NAME")
Iswww = InStr(ServerName,"www.mysite.com")

If Iswww < 1 Then
NewLocation = "http://www.mysite.com" & PathInfo
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", NewLocation
End If
%>

Any comment on this code please welcome.

Thanks for the reply.

mrMister

12:02 pm on Jul 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your code is for a specific purpose. Mine is more general. In essence they both do the same thing.

The only non-cosmetic difference is that mine calls Response.End

Response.End prevents any data being added after the 301 which could confuse some HTTP clients.