Hi everyone,
This has been a most informative thread!
My site is ASP based running on II6 at WebCentral.com.au
I have two domains - one is an abbreviated version of the other which is primarily used for email as it's shorter. They are ratb.com.au and rockaroundtheblock.com.au
I can see Google is indexing both domains which is bad, due to duplicate content. I want the long domain used as the web address.
What I want to do is detect which domain has been used to enter the site, and then 301 redirect it to the other. I've put this code into global.asa but it only works when entering the domain - if someone enters via a bookmarked / google indexed link it doesn't work.
[codebox]Sub Session_OnStart
dim safeURL
'***** ONLY CHANGE THE LINE BELOW *****
safeURL = "rockaroundtheblock.com.au" 'domain name
'***** ONLY CHANGE THE LINE ABOVE *****
dim requestedURL
dim requestedWithPre
dim pre
dim sendTo
pre = "www."
requestedURL = LCase(Request.ServerVariables("SERVER_NAME"))
If InStr(1, requestedURL, "www.", 1) = 1 Then requestedWithPre = True
If (requestedURL <> safeURL) AND (requestedURL <> pre & safeURL) Then
sendTo = "http://"
If requestedWithPre Then
sendTo = sendTo & pre & safeURL
Else
sendTo = sendTo & safeURL
End If
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", sendTo
End If
End Sub
[/codebox]
My host webcentral has provided this code but I can't get it to work
[codebox]
ASP Driven Multiple Domain Redirection
Web sites are typically attached to an IP address, but sometimes several domain names may point to the same IP. A clever ASP script could display the same page different ways, or one of several different pages, depending on which domain name was typed utilizing the HTTP_HOST server variable. Our site, for example has four domain names tied to the same IP ( domain1.com, domain2.com domain3.com and domain4.com ) and the following script will provide different results depending on what domain name it is called from:
<%response.buffer=true%>
<%
Dim theSRV
theSRV = Request.ServerVariables("SERVER_NAME")
Select Case theSRV
Case "www.domain1.com" Response.Redirect("/page1.htm")
Case "www.domain2.com" Response.Redirect("/page2.htm")
Case "www.domain3.com" Response.Redirect("/directory1")
Case "www.domain4.com" Response.Redirect("/directory2")
End Select
%>
<HTML>
<BODY>
To alter this code, simply replace the sections currently highlighted in blue, with your own domain names and your own directories.
This will mean that when a user enters www.domain1.com they will see www.domain1.com/page1.htm; www.domain3.com will return www.domain3.com/directory1 etc, making the redirection process appear just a little more seamless. You could replace the values with anything you would like, relative path's, as included in the example, or fully qualified remote paths to redirect your users to one of your sites on a completely different server.
The same Code Principles can be used for other variables also, such as redirecting token users based on there user name, or using the Response.Write function instead of Response.Redirect to simply generate a different page on the fly. [/codebox]
I've tried entering the "Case" line as
Case "www.ratb.com.au" Response.Status = "301 Moved Permanently" Response.addheader "Location", "
http://www.rockaroun...eblock.com.au/" Response.End
but that doesn't work either!
What I really want to figure out is how to redirect a page by switching out ratb and replacing it with rockaroundtheblock