This is targeted towards people who have their website hosted for them, and do not have access to features in IIS.
I
was faced with a challenge recently from a client that wanted to change
their very well established domain name to a completely new one...But
didn't want to upset their rankings!!??
The domain they were
using is very well ranked, and that literally had 100's of pages that
were ranking very well individually - So just a 301 re-direct on the
root of the domain was out of the question.
I decided to
write a little sub procedure that would check to see if people were
accessing the page via the old domain name, and if so 301 re-direct to
the page on the new domain.
Here's the sub I
wrote below, I hope it helps anybody faced with the same problem.. It
will take into account ALL parameters and folder structure for you -
You just need to put it in the <HEAD> of your page.
Sub Dynamic301redirect()
dim ServerName, OldDomain, SitePathInfo, NewDomain, TheQueryString
ServerName = Request.ServerVariables("SERVER_NAME") & ""
SitePathInfo = Request.ServerVariables("PATH_INFO") & ""
TheQueryString = request.ServerVariables("QUERY_STRING") & ""
If TheQueryString <> "" then
TheQueryString = "?" & TheQueryString
End If
'Here you need to put the old domain, and the new domain (just www.domain.com)
OldDomain = "www.your-old-domain-name.co.uk"
NewDomain = "www.your-new-domain-name.co.uk"
ServerName = ServerName & SitePathInfo & TheQueryString
NewDomain = NewDomain & SitePathInfo & TheQueryString
OldDomain = OldDomain & SitePathInfo & TheQueryString
IF lcase(ServerName) = OldDomain then
ServerName = Request.ServerVariables("HTTP_REFERER") & ""
IF instr(ServerName, OldDomain) = 0 then
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://" & NewDomain
end if
end if
End Sub
Call Dynamic301redirect()
I
will be putting up another script soon that checks to see if people are
accessing with WWW or without and you can redirect appropriately.