Forum Moderators: open

Message Too Old, No Replies

Redirect .domain to www.domain in ASP

Emergency code help needed

         

BennyBlanco

3:50 pm on Sep 21, 2005 (gmt 0)

10+ Year Member



Hey guys,

I have a client who has ASP sites and used to hold top spot for years in his industry. Recently, some scraper used a URL for his sites that had no www. and now he is getting dup content hit. I know that I need to do a 301 or 302 being that it is on a windows box, but I am not sure since most of my experience is in apache and php.

Can anyone please provide me with detailed instructions on performing the proper redirect, server-side, for asp?

Thanks All.

Benny

Easy_Coder

5:01 pm on Sep 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Response.Status="301 moved permanently"
Response.AddHeader "Location", "http://www.newlocation.com/"

BennyBlanco

5:24 pm on Sep 21, 2005 (gmt 0)

10+ Year Member



Thanks coder, but is that for a single page? I want to redirect all site traffic to the www. version. Where would I put it.

emsaw

6:16 pm on Sep 21, 2005 (gmt 0)

10+ Year Member



BennyBlanco,

try this for classic ASP:
In global.asa


sub Session_OnStart
' code to check www vs non-www
end sub

-Mark

BennyBlanco

7:50 pm on Sep 22, 2005 (gmt 0)

10+ Year Member



Thanks for the help guys, but nothing seems to be right. Specifically, I have a global.asax file that I am working with. If someone could please paste me the code I need to insert on this page to make the redirect work, I would be forever grateful.

asp4bunnies

8:23 pm on Sep 22, 2005 (gmt 0)

10+ Year Member



Here's what I'd do:

1) Make an empty directory on your server and place into it a single page called 404.asp

2) Change your home directory in IIS to point to that directory.

3) In IIS, change your custom error for 404s to point to that relative URL (i.e. Select Relative URL and type in /404.asp)

The content of /404.asp should be:

<%@LANGUAGE="VBScript"%>
<%

Dim varFile:varFile = Request.querystring
Dim requestpage:requestpage = replace(varFile,"404;","")
Dim splitFile:splitFile = Split(requestpage,"?")
Dim splitnewFile:splitnewFile = Split(requestpage,":")

Dim newpage
newpage = splitnewfile(2)
If instr(newpage,"/") > 0 then
newpage = mid(newpage,(instr(newpage,"/") + 1))
Else
newpage = ""
End if

response.redirect "http://www.whatever.com/" & newpage
%>

emsaw

3:29 pm on Sep 23, 2005 (gmt 0)

10+ Year Member



if it's a global.asax file, then you are using ASP.net . in your original post, you said ASP . :o

put your code in either of the following, depending on how often you really need to check the url:

this is ASP.net C#


protected void Session_Start(Object sender, EventArgs e)
{
}
protected void Application_BeginRequest(Object sender, EventArgs e)
{
}