ASP script : response.redirect

  Chris69 11:43 23 Feb 2004


My MS web host tells me I have to use some script to redirect domain names to sub-webs/directories within my web, if I am to retain MS Frontpage functions.

I've tried following their (inadequate) instructions but to no avail, and their support service is no help either (surprise !!).

Can anyone advise ?

What I've done is :

1. Created new page in the root directory of my web and named that page default.asp

2. I've deleted all html coding in the page and replaced it with :

host = Request.ServerVariables("HTTP_HOST")
if host = "" or host = "click here" then
response.redirect("click here")
elseif host = "" or host = "click here" then
response.redirect("click here")
elseif host = "" or host = "click here" then
response.redirect("click here")
' if we get no host or undefined host
response.redirect("click here")
end if

3. I've saved that page and uploaded to my web (whilst retaining the default.htm page in the root directory also)

Any ideas ? Sorry - but I'm an absolute beginner on ASP coding etc !!

Many thanks !!


  Taran 13:18 23 Feb 2004

This is off the top of my head - I've not tried it to verify it and I'm a bit pushed for time at present so, fingers crossed...


EnableSessionState=False host = Request.ServerVariables("HTTP_HOST")

If host = "URL" then then

response.redirect "target URL"

else if host = "URL" then

response.redirect "target URL"

else if host = "URL" then

response.redirect "target URL"


response.redirect "target URL"


Include your hostnames in the If/else list without an 'or' to separate them. The last entry can simply be 'else >> do this action' since all the other bases should have been covered throught he rest of the statement.

Note that this is not necessarily the most efficent method but it is about the simplest to get your head around.

I suggest that you go back to your host and ask if they will allow server.transfer instead of response.redirect. If you have variables that you want to pass onto the target page from the redirect page then server.transfer does this far more efficiently than does.

I'll look in on this later if I get more time to actually play with the code. As I said this is a "first glance" reply, so don't take it as gospel and try it on a non-ctrictal environment to play with it.

  Chris69 16:52 23 Feb 2004


Many thanks for taking the time to reply, but having (I think !) changed the code as suggested, it still doesn't work ! The browser just goes to the root directory's default.htm every time whichever domain name I type in ...

A few really idiot questions from me (I've never asp'd before !):

1. The web host put (brackets) around the target URLs - is this right or wrong ?

2. Did you mean to type the "then then" in the first option (I presumed it was a typo in your haste !)

3. Do I need to include the following at the top before any of the script ?

<%@ Language="Vbscript" %>

4. Do I leave the default.htm file in the root directory unchanged ?

5. Should I identify the default.asp page/file as the "home page" in Frontpage 2002, or leave the default.htm as the home page ?

The above just occur to me as stupid/simple reasons why I can't get it to work !

Any other reasons you/others can think of ?

I'd be rally grateful for any thoughts you could share !

Thanks again


  Chris69 17:06 23 Feb 2004


To try to see whatthe problem may be, I've tried opening the default.asp page in the browser. When I do so I get :


Microsoft VBScript compilation error '800a03f6'

Expected 'End'

/default.asp, line 23

But when I do that and refresh I get :

Microsoft VBScript compilation error '800a03f4'

Expected 'If'

/default.asp, line 23

else response.redirect "click here" End
But when I do that and refresh I get :

Microsoft VBScript compilation error '800a03f6'

Expected 'End'

/default.asp, line 23

---------------aaagh !!!!!!!!!!!!!!!!

  Chris69 17:54 23 Feb 2004


Well I seem to have fixed the above compilation errors through having the following at the end of the script :

end if


But the script still doesn't work - all domain names just go to root default.htm ...

Thanks for any ideas anyone may have !


  Taran 08:45 24 Feb 2004

Can you confirm for me whether the redirect script is to be used on page[s] outside the target site you want to lead people to ?

What I mean is, are the redirect pages on an external site - a different domain entirely, or are they to capture domain name requests and redirect to an alternative address, on a subweb maybe, within your main site ?

I had a brief play this with ASP this morning on a Windows server [only had Apache available over the weekend due to technical problem] and came up with some workable solutions.

My apologies for posting my initial effort above. After weeks of PHPing with PHP very much 'on the brain' I can't believe I suggested such an awful mismatch of ASP and expected it to work at all.

Give as much detail as possible about where the target pages will be in relation to the source page[s] that will direct visitors to them.

I get the impression from your first examlpe that domain name requests are to be used to send visitors to specific subwebs on one parent site.

If this is the case can you confirm and explain the overall site structure ?

  IClaudio 09:19 24 Feb 2004

I know nothing about ASP beyond a few basics, so Taran can correct me! But:

The default.asp code doesn't live on an HTML page - you just use NotePad or similar text editor and put this in your root folder.

The following code is what I knocked up for one of my sites, though in the end, I didn't use FP extensions, so don't know if it will work!

host = Request.ServerVariables("HTTP_HOST")

if host = "[your first sub-domain]" or host="www. [your first sub-domain]" then

response.redirect("http://[your main site]/[the folder where your first subdomain lives]/default.htm")

elseif host = [more of the same code pointing at any other sub-domains you may have]

' ignore all this if a wrong hostname is typed in...
response.redirect("http://[ your main site ]/default.htm")end if


Hope that helps, good luck!


  IClaudio 09:23 24 Feb 2004

I just noticed that the code I put up there ^^ is essentially what Taran gave you in the beginning, and he calls it 'awful', so you should probably ignore it!


  Taran 10:21 24 Feb 2004

I'll post a simlpe working sample that you can mod to your hearts content to get you going and if you need more we;ll see what can be done.

<% Dim HTTPHost HTTPHost = Lcase(Request.ServerVariables("HTTP_HOST"))

If HTTPHost = "DomainName1" then

Response.Redirect ("TargetURL/subweb1") End If

If HTTPHost = "DomainName2" then

Response.Redirect ("TargetURL/subweb2") End If %>

That works a treat - I've played with it on an IIS server.

Another alternative sould be:

sname = Request.ServerVariables("SERVER_NAME")

sname = ucase(sname)

if InStr(sname,"YOURDOMAIN1") <> 0 then

response.redirect "TargetURL/subweb1"

elseif InStr(sname,"YOURDOMAIN2") <> 0 then

response.redirect "TargetURL/subweb2"

elseif........ Add more if required

end if

This second option also works nicelt but keep in mind the case sensitivity of it. The commands:

sname = Request.ServerVariables("SERVER_NAME")

sname = ucase(sname)

mean that the name of the requested URL needs to be capitalised, which is why the if statement runs along like this:

if InStr(sname,"YOURDOMAIN1") <> 0 then

If you want to use it, you absolutely MUST type the referring domain name in capitals.

Either one works perfectly well, but I'd try the first option if I were you and see where you get.

Sorry once again for mangling my first attempt. I was pushed for time and completely overdosed on PHP. Switching back and forth between languages becomes blurred at times - well, it does to me anyway.


Good luck with it.

  Chris69 11:26 24 Feb 2004

I've tried Tazan's first option above (appears most similar to what my webhost (1+1) suggest), but still won't work !

When I open the default.asp page in my browser I get an error message :

Microsoft VBScript compilation error '800a0401'

Expected end of statement

/default.asp, line 1

Dim HTTPHost HTTPHost = Lcase(Request.ServerVariables("HTTP_HOST"))
(arrow points at second HTTPHost)

Sorry to be a real pain - I really appreciate your help and time !! - but :

1. Any suggestion of how I correct the above ?

If I do that and it still doesn't work (I'm trying to redirect different domain names to different sub-webs within my main site - I have set up 3 folders in the root directory [which contains the default.asp and its own default.htm pages/files], identified each sub-folder as a sub-web and each has it's own default.htm page/file that I am trying to redirect different domain names to) :

- should I have a language line at the top of the page (some peoples' suggestions include one)

- is it OK for me to be creating the default.asp page within MS Frontpage, as a page (in HTML view) and then saving to root directory. Should I just use Notepad ?

- should I be including the "http://" in front of my target URLs ?

- should I have () brackets around the target URLs (some suggestions have included them, others not)

- should I retain (as I have at present) the previously existing default.htm file as my home page in the root, or should I make the default.asp file my home page (in which case do I just rename the existing default.htm file ?)

- or any other suggestions why a beginner like me is making this so difficult ??? (e.g. I have opened the root folder on the web host's site and checked its Properties do enable scripts to run - could there be other equally obvious - to those who know ! - things I should check ??

Needless to say in the time it's taken several of you kind people to reply I haven't heard a whisper from the web host's so-called "support" service !! And it's their proposed solution I'm trying to implement !

Thanks again for all your help !!

best wishes


  Taran 11:40 24 Feb 2004

I didn't hink I need to include the


Add it to the above.

Compilation errors are normally the result of a language definition not being set, or the wrong definition being used {VBScript set with JScript code in the page fpr example] or sometimes where a statement ends unexpectedly.

Try the first example I gave you above but drop the <%@LANGUAGE="VBSCRIPT"%> line before all the others.

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

OnePlus 5T review: Hands-on

Illustrator Andrés Lozano on his improv line work, brazen use of colours & hand sketching

iPhone X review

Comment envoyer gratuitement des gros fichiers ?