Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Redirect based upon typed URL?
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Carefree
Advanced Member

Philippines
4207 Posts

Posted - 24 February 2005 :  09:59:21  Show Profile
Is there a method to redirect an incoming port 80 request to another port based upon the address requested?

DarkDrift
Junior Member

USA
126 Posts

Posted - 24 February 2005 :  10:02:56  Show Profile  Visit DarkDrift's Homepage  Send DarkDrift an AOL message
try the
select case Request.QueryString("")
case "http://www.domain.com"
response.redirect("http://www.domain.com:**PORT**
case "http://www.otherdomain.com"
response.redirect("http://www.domain.com:**PORT**
case else
response.redirect("http://www.domain.com:**PORT**
end select

If you figure out host headers you can do it also.. I am just not too sure on that.. I think that will work!

http://www.xcalliber.com - The Future of Boards

Edited by - DarkDrift on 24 February 2005 10:04:25
Go to Top of Page

Carefree
Advanced Member

Philippines
4207 Posts

Posted - 24 February 2005 :  22:17:05  Show Profile
I tried this but EVERY request forwards to 8080.
<%
select case Request.QueryString("")
	case "http://carefreecomputing.net"
		If Request.ServerVariables("SERVER_PORT")=80 then 
                	strSecureURL = "https://"
			strSecureURL = strSecureURL & Request.ServerVariables("SERVER_NAME")
			strSecureURL = strSecureURL & Request.ServerVariables("URL")
			if request.Querystring <> "" then
				strSecureURL = strSecureURL & "?" & request.Querystring
			end if
			Response.Redirect strSecureURL
		End If
	case "http://othersite.com"
		response.redirect("http://carefreecomputing.net:8080")
	case else
		response.redirect("http://carefreecomputing.net:8080")
end select
%>


The reason for the if/then routine is to allow indexing. Indexing will not occur with a secured site, this routine SHOULD redirect a browser to use SSL and allow an indexing spider to use port 80.


Using this code has the same effect (so it's not in the spider routine)
<%
select case Request.QueryString("")
	case "http://carefreecomputing.net"
		Response.Redirect("https://carefreecomputing.net")
	case "http://othersite.com"
		response.redirect("http://carefreecomputing.net:8080")
	case else
		response.redirect("http://carefreecomputing.net:8080")
end select
%>


However, since I haven't got the bugs out of the querystring object, it's a moot point. It looks like QueryString comes up empty all the time, regardless of what's typed in the browser address bar.



Edit




Figured it out using a different approach.

Instead of QueryString, I did this:


<% select case Request.ServerVariables("server_name")
	case "carefreecomputing.net"
		If Request.ServerVariables("SERVER_PORT")=80 then 
                	strSecureURL = "https://"
			strSecureURL = strSecureURL & Request.ServerVariables("SERVER_NAME")
			strSecureURL = strSecureURL & Request.ServerVariables("URL")
			if request.Querystring <> "" then
				strSecureURL = strSecureURL & "?" & request.Querystring
			end if
		End If
		response.redirect("https://carefreecomputing.net/index.htm")
	case "othersite.com"
		response.redirect("http://carefreecomputing.net:8080")
	case else
		response.redirect("https://carefreecomputing.net/index.htm")
end select%>

Edited by - Carefree on 25 February 2005 00:35:27
Go to Top of Page

DarkDrift
Junior Member

USA
126 Posts

Posted - 25 February 2005 :  01:40:14  Show Profile  Visit DarkDrift's Homepage  Send DarkDrift an AOL message
It is forwarding to 8080 cause it says
response.redirect("htt.......:8080

if i am wrong take out the case else and check for errors

http://www.xcalliber.com - The Future of Boards

Edited by - DarkDrift on 25 February 2005 01:41:01
Go to Top of Page

Carefree
Advanced Member

Philippines
4207 Posts

Posted - 26 February 2005 :  01:38:27  Show Profile
OK - for anyone else out there who ever wanted to host multiple sites using ports vs multiple NICs and IP addresses; here's how I got it to work:

<%
select case Request.ServerVariables("http_referer")
	case "http://othersite.net"
		response.redirect("http://othersite.net:8080")
	case "http://othersite.com"
		response.redirect("http://othersite.com:8080")
	case "http://www.othersite.net"
		response.redirect("http://othersite.net:8080")
	case "http://www.othersite.com"
		response.redirect("http://othersite.com:8080")
end select
select case Request.ServerVariables("server_name")
	case "carefreecomputing.net"
		If Request.ServerVariables("SERVER_PORT")=80 then 
                	strSecureURL = "https://"
			strSecureURL = strSecureURL & Request.ServerVariables("SERVER_NAME")
			strSecureURL = strSecureURL & Request.ServerVariables("URL")
			if request.Querystring <> "" then
				strSecureURL = strSecureURL & "?" & request.Querystring
			end if
		response.redirect("https://carefreecomputing.net/index.htm")
		End If
	case "othersite.net"
		response.redirect("http://othersite.net:8080")
	case "othersite.com"
		response.redirect("http://othersite.com:8080")
	case else
		response.redirect("https://carefreecomputing.net/index.htm")
end select
%>


Simply change the "othersite" to the name of the site people are trying to reach (hosted on your computer) and the port number from "8080" to whatever you are using.

Change "https://carefreecomputing.net/index.htm" to the entrance page of your main website.


A bit of explanation:

Apparently, the variable server_name will not work with the www. prefix; so you need to use the http_referer to handle that problem. Also, if you use a Case Else in the http_referer; everything will get redirected to that URL:Port.

Next issue - since search engines cannot index secure sites; if you want people to find you, you have to get around that limitation. The if/then routine after the Server_Name request lets search engines access the site as though it wasn't secure, but forces browsers to use SSL.

If your site isn't a secure one, then simply strip out that entire if/then routine.

Save the page as default.asp (or whatever) and make it the default page in IIS for your server. Done.

Edited by - Carefree on 26 February 2005 01:42:44
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.23 seconds. Powered By: Snitz Forums 2000 Version 3.4.07