Forum Moderators: open

Message Too Old, No Replies

ASP Redirect

From and older message

         

Hardwood Guy

4:40 pm on Sep 1, 2003 (gmt 0)

10+ Year Member



Hey Guys:

This asp redirect has confused me endlessly and I don't know why. It may look simple to some but....I can't get it right. In fact I've been over writing sites because I don't know the proper code. Now I have one that I've wanted to update for weeks but afraid it will "shut down" my other site.

A have also found I have three versions of the same site floating around in cyberland(because of the asp thingie) but it doesn't seem to be causing problems. I love the server I deal with and they helped in the beginning but refuse to do so anymore.

Question: I have two sites. I had the code right at one time but deleted the home page from Front Page that I am using for fear I'd screw it up again...Let's call the two sites.. Hardwood and Florida.

From my understanding the code should be placed before any html tag? So....it goes like this?

<%
sname = Request.ServerVariables("SERVER_NAME")
sname = ucase(sname)
if InStr(sname,"FLORIDA") <> 0 then
response.redirect "florida"
else
response.redirect "default.html"
end if

<html>

<head>

I dug up this example in and older message thread as shown below, but I don't see a close tag? Probably another dummy question... but here goes. Does this code have to be on both sites? In another example we have three sites and I'll call the other one "Installer."

According to the example it should go like this...

<%
sname = Request.ServerVariables("SERVER_NAME")
sname = ucase(sname)
if InStr(sname,"HARDWOOD") <> 0 then
response.redirect "hardwood"
elseif InStr(sname,"FLORIDA") <> 0 then
response.redirect "florida"
elseif InStr(sname,"INSTALLERS") <> 0 then
response.redirect "installers"
elseif........
end if

<html>

<head>

Any help would be greatly appreciated..so I can get over this frustration and fear.

----------------------------------------------------------
For my multilingual site, I have recently aquired an additional URL that I want to point to a subdirectory of my domain, for the purpose of improved marketing. I will be using similar, but not the same content, so I am not worried about duplicate content penalties.
However, is the following redirect procedure, which is recommended by my host, the best one?

My goal is to have no problem with spidering and to see my new url getting ranked.

----------
Using ASP code, you can detect which URL a person is browsing to your site with, and redirect them to the appropriate place on your site. Here is some example code that will do the job, put this at the very top of an .ASP page, before any HTTP tags:
<%
sname = Request.ServerVariables("SERVER_NAME")
sname = ucase(sname)
if InStr(sname,"DOMAIN1") <> 0 then
response.redirect "subdirectory to go to"
elseif InStr(sname,"DOMAIN2") <> 0 then
response.redirect "2nd subdirectory to go to"
elseif........
end if

Make sure that the domains in the InStr commands are capital letters. For example, suppose you have two domains, apple.com and banana.com, pointing to the same web site. On this site there is an "appledir" subdirectory (or sub-web) and a "bananadir" subdirectory. Then the code will look like this:

<%
sname = Request.ServerVariables("SERVER_NAME")

sname = ucase(sname)
if InStr(sname,"APPLE") <> 0 then
response.redirect "appledir"
elseif InStr(sname,"BANANA") <> 0 then
response.redirect "bananadir"
end if

If you have only two domains and you still need the primary domain to poin to the root of the site then you can use this code:

<%
sname = Request.ServerVariables("SERVER_NAME")
sname = ucase(sname)
if InStr(sname,"DOMAIN2") <> 0 then
response.redirect "domain"
else
response.redirect "index.html"
end if

aspdaddy

7:33 pm on Sep 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey you have me confused too :), what is it you are tryin to do with response.redirect -
its a very simple concept

response.redirect strURL

>My goal is to have no problem with spidering and to see my new url getting ranked.

Then I would stay away from redirecting, but maybe others can argue with this, I prefer to play safe and not redirect in you way you have described.

Hardwood Guy

8:55 pm on Sep 1, 2003 (gmt 0)

10+ Year Member



Hey Daddy:

Just trying to get the danged thing straight. A year ago when I didn't know beans about all this stuff I started an account with the asp thingie. Another words I was sold on using it so I could place more than one site under one domain while paying less for the web hosting.

I have no problems with being seen. I'm just lost.

mattur

9:27 pm on Sep 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's confused me as well ;) What are you actually trying to do here?!

aspdaddy

9:36 pm on Sep 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>sname = Request.ServerVariables("SERVER_NAME")

The only time I used this was when I had the same pages on more than one server (TEST/PROD), and needed to select the rightr database.

For what you are doing seems the opposite - many sites/one server. So SERVER_NAME wil allways be the same thing?

>From my understanding the code should be placed >before any html tag
You can avoid this by puting

Response.Buffer=true

at the top of the page.

Good Luck :)

Hardwood Guy

11:53 pm on Sep 1, 2003 (gmt 0)

10+ Year Member



Thanks anyway guys...maybe I'm in the wrong place? I want to get one site republished. I've avoided the default page because that's where the danged code is supposed to be. Maybe I'll just publish the rest and leave it go for now...it doesn't get affectd that way. I'm gonna talk to that dude who talked me into this crap...if I can find him.

Severly stumped...been that way for five months

Zaphod Beeblebrox

2:33 pm on Sep 2, 2003 (gmt 0)

10+ Year Member



>> So SERVER_NAME wil allways be the same thing?

Nope, if you host multiple domains on 1 IP it will contain everything before the first slash, so "www.myfirstdomain.com" or "www.myseconddomain.com".

I host a couple of sites that way, and this lets me determine how to redirect the user to the correct site.

BTW - the pages I redirect to are eventually indexed by Google, for example, so I don't think it's too much of a problem for searchengines to use this method.

I use something like this (not precisely this, but similar in concept):


Set objRs = objCon.execute ("SELECT * FROM Domains WHERE Domain='" & Request.ServerVariables("server_name") & "'")
If Not objRs.EOF Then
'Closing Recordset and Database should be done here
Response.Redirect objRs("Redirect")
Response.End
End If

The Domains table contains the fields "Domain" and "Redirect", where Domain would contain things like "www.mydomain.com" and Redirect would contain "/main/index.htm".

aspdaddy

9:44 pm on Sep 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes Zaphod Beeblebrox is right, SERVER_NAME will show the different domain names on a virtual server - sorry bout that :)

I was thinking of a project where the servers were named \\UKSTX_DEV, \\UKSTX_PROD etc so the SERVER_NAME was used to identify dev or prod.

Put something like this as your index/default file should do the trick:

<%
Response.buffer=true
select case (Request.ServerVariables("SERVER_NAME"))
case "www.domain1.com"
Response.redirect "/domain1/"
case "www.domain2.com"
Response.redirect "/domain2/"
' add more cases here
end select
%>

Personally I stay away from these kind of redirecting, maybe it works okay with G at the momennt, but hosting is cheap - why bother

Zaphod Beeblebrox

12:42 pm on Sep 5, 2003 (gmt 0)

10+ Year Member



Because hosting on your own webserver, via your own ADSL connection is cheaper... :o)