Dynamic Redirect

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to create page in which user will enter their zipcode and they
will be redirected to page associated with that zipcode. If zipcode enter is
not found then they will be redirected to generic page. I am assuming this
will require some sort of database in the background. Listbox would be out
of question since there are hundreds of zipcodes.

I've called MS tech support and they were not able to assist me unless I use
their advisory service which is $210 per hour.

I am hoping someone has done this in the past and be able to provide some
guidance.

Thanks,
Deven
 
Requires a database of zipcodes, etc. and server-side scripting which is based on what is supported
by your web host.

--
==============================================
Thomas A. Rowe
Microsoft MVP - FrontPage
==============================================
Agents Real Estate Listing Network
http://www.NReal.com
==============================================
 
Hi,
A database would be the best solution. Alternative if you have pages such as
www.you.com/12345.htm were 12345 is a zip code you could ask the user for
his code then redirect - if there's no page for his zip code send him to a
nice custom error page. This solution is inferior but it might be an option
if you don't want to use a database

Jon
 
Database would be best solution but I was hoping someone would either direct
me to the website or KB article that shows me how this is done. I am not
programmer so I would not know how to code it. I know how to link to
database and view DB results, etc..
 
This requires custom ASP/VBScript unless you can locate a pre-written application that does what you
want.

--
==============================================
Thomas A. Rowe
Microsoft MVP - FrontPage
==============================================
Agents Real Estate Listing Network
http://www.NReal.com
==============================================
 
Jon said:
Hi,
A database would be the best solution. Alternative if you have pages
such as www.you.com/12345.htm were 12345 is a zip code you could ask
the user for his code then redirect - if there's no page for his zip
code send him to a nice custom error page. This solution is inferior
but it might be an option if you don't want to use a database

Jon

Following up on Jon's idea I have found this ASP code which does the testing
for existence of the page

I have amended it (but not tested it) to accept a zipcode as input and
redirect to a page using that code. If that page doesn't exist, redirect to
errror.html

<html>
<!-- testurl.asp -->
<head>
<title>Test URL</title>
</head>
<body>
<%
Dim cURL
cURL = "http://your.com/" & Request("zipcode") & ".htm"
Const errorURL = "http://your.com/error.html"
If UrlExists(cURL) Then
Response.Redirect(cURL)
Else
Response.Redirect(errorURL)
End If

Function UrlExists(xURL)
On Error Resume Next
Err.Clear
Dim objXML
Set objXML = CreateObject("Microsoft.XMLHTTP")
objXML.Open "HEAD",xURL,False
objXML.Send
If Err.Number <> 0 Or objXML.Status <> 200 Then
UrlExists = False
Else
UrlExists = True
End If
Set objXML = Nothing
End Function
%>
</body>
</html>

This would be called by
<form method="post" action="testurl.asp">
Enter zipcode:
<input type="text" name="zipcode" value="" />
<input type="submit" value="Submit" />
</form>

The original code (before I amended it) works in IE7.

I am curious to know whether this will work in all browsers.
That is, is Microsoft.XMLHTTP specific to IE ?
 
Thanks Trevor. I will try your script and see if it works for me.

Deven

Trevor L. said:
Jon said:
Hi,
A database would be the best solution. Alternative if you have pages
such as www.you.com/12345.htm were 12345 is a zip code you could ask
the user for his code then redirect - if there's no page for his zip
code send him to a nice custom error page. This solution is inferior
but it might be an option if you don't want to use a database

Jon

Following up on Jon's idea I have found this ASP code which does the testing
for existence of the page

I have amended it (but not tested it) to accept a zipcode as input and
redirect to a page using that code. If that page doesn't exist, redirect to
errror.html

<html>
<!-- testurl.asp -->
<head>
<title>Test URL</title>
</head>
<body>
<%
Dim cURL
cURL = "http://your.com/" & Request("zipcode") & ".htm"
Const errorURL = "http://your.com/error.html"
If UrlExists(cURL) Then
Response.Redirect(cURL)
Else
Response.Redirect(errorURL)
End If

Function UrlExists(xURL)
On Error Resume Next
Err.Clear
Dim objXML
Set objXML = CreateObject("Microsoft.XMLHTTP")
objXML.Open "HEAD",xURL,False
objXML.Send
If Err.Number <> 0 Or objXML.Status <> 200 Then
UrlExists = False
Else
UrlExists = True
End If
Set objXML = Nothing
End Function
%>
</body>
</html>

This would be called by
<form method="post" action="testurl.asp">
Enter zipcode:
<input type="text" name="zipcode" value="" />
<input type="submit" value="Submit" />
</form>

The original code (before I amended it) works in IE7.

I am curious to know whether this will work in all browsers.
That is, is Microsoft.XMLHTTP specific to IE ?

--
Cheers,
Trevor L.
[ Microsoft MVP - FrontPage ]
MVPS Website: http://trevorl.mvps.org/
 
I think you'd be better checking for the existance for the file rather than
url. For example say you have a folder called Test and you want to check if
Page1.htm exists in that folder you could do.
<%
set f = createobject("scripting.filesystemobject")
if f.fileexists(server.mappath("/Test/Page1.htm")) then
response.redirect "/Test/Page1.htm"
else
response.redirect "error.htm"
end if
set f = nothing
%>

A drawback with your method is I'm fairly sure (though wouldn't swear to it)
that if you have a custom error page set in IIS a missing page will actually
return a 200 OK response code so you'd have no way to determine from the
response code whether you're getting the page you want or the error page

Jon

Trevor L. said:
Jon said:
Hi,
A database would be the best solution. Alternative if you have pages
such as www.you.com/12345.htm were 12345 is a zip code you could ask
the user for his code then redirect - if there's no page for his zip
code send him to a nice custom error page. This solution is inferior
but it might be an option if you don't want to use a database

Jon

Following up on Jon's idea I have found this ASP code which does the
testing for existence of the page

I have amended it (but not tested it) to accept a zipcode as input and
redirect to a page using that code. If that page doesn't exist, redirect
to errror.html

<html>
<!-- testurl.asp -->
<head>
<title>Test URL</title>
</head>
<body>
<%
Dim cURL
cURL = "http://your.com/" & Request("zipcode") & ".htm"
Const errorURL = "http://your.com/error.html"
If UrlExists(cURL) Then
Response.Redirect(cURL)
Else
Response.Redirect(errorURL)
End If

Function UrlExists(xURL)
On Error Resume Next
Err.Clear
Dim objXML
Set objXML = CreateObject("Microsoft.XMLHTTP")
objXML.Open "HEAD",xURL,False
objXML.Send
If Err.Number <> 0 Or objXML.Status <> 200 Then
UrlExists = False
Else
UrlExists = True
End If
Set objXML = Nothing
End Function
%>
</body>
</html>

This would be called by
<form method="post" action="testurl.asp">
Enter zipcode:
<input type="text" name="zipcode" value="" />
<input type="submit" value="Submit" />
</form>

The original code (before I amended it) works in IE7.

I am curious to know whether this will work in all browsers.
That is, is Microsoft.XMLHTTP specific to IE ?

--
Cheers,
Trevor L.
[ Microsoft MVP - FrontPage ]
MVPS Website: http://trevorl.mvps.org/
 
Jon said:
I think you'd be better checking for the existence for the file
rather than url. For example say you have a folder called Test and
you want to check if Page1.htm exists in that folder you could do.
<%
set f = createobject("scripting.filesystemobject")
if f.fileexists(server.mappath("/Test/Page1.htm")) then
response.redirect "/Test/Page1.htm"
else
response.redirect "error.htm"
end if
set f = nothing
%>

A drawback with your method is I'm fairly sure (though wouldn't swear
to it) that if you have a custom error page set in IIS a missing page
will actually return a 200 OK response code so you'd have no way to
determine from the response code whether you're getting the page you
want or the error page

Jon,
Sorry I took so long to reply

I was looking at this for my own use as much as for the OP.

My thoughts on reading your code was:
How can I test for a file on a server?
Aren't files just local objects (i.e. on your own hard disk)?

But I gave it a go today
<body>
<%
Const cfile = "indexx.html"
Dim destfile
destfile = "zipcodeerror.html"

set f = createobject("scripting.filesystemobject")
if f.fileexists(server.mappath(cfile)) then
destfile = cfile
end if
set f = nothing
response.redirect destfile
%>

Sure enough
when cfile = "index.html", I went to that page on the server
when cfile = "indexx.html", I went to "zipcodeerror.html" on the server.

Actually, since I have a default error404 page, this works just as well
<%
Const cfile = "indexx.html"
response.redirect cfile
%>

But in the context of going to a page for a specific postcode (sorry
zipcode, my Australian-ness showing here), it would be better to use a
specific error page.

I will peruse MS Windows Script Technologies to further my knowledge of
(inter alia) filesystemobject
 
Some web host do not allow access to the FileSystemObject.

--
==============================================
Thomas A. Rowe
Microsoft MVP - FrontPage
==============================================
Agents Real Estate Listing Network
http://www.NReal.com
==============================================


Trevor L. said:
Jon said:
I think you'd be better checking for the existence for the file
rather than url. For example say you have a folder called Test and
you want to check if Page1.htm exists in that folder you could do.
<%
set f = createobject("scripting.filesystemobject")
if f.fileexists(server.mappath("/Test/Page1.htm")) then
response.redirect "/Test/Page1.htm"
else
response.redirect "error.htm"
end if
set f = nothing
%>

A drawback with your method is I'm fairly sure (though wouldn't swear
to it) that if you have a custom error page set in IIS a missing page
will actually return a 200 OK response code so you'd have no way to
determine from the response code whether you're getting the page you
want or the error page

Jon,
Sorry I took so long to reply

I was looking at this for my own use as much as for the OP.

My thoughts on reading your code was:
How can I test for a file on a server?
Aren't files just local objects (i.e. on your own hard disk)?

But I gave it a go today
<body>
<%
Const cfile = "indexx.html"
Dim destfile
destfile = "zipcodeerror.html"

set f = createobject("scripting.filesystemobject")
if f.fileexists(server.mappath(cfile)) then
destfile = cfile
end if
set f = nothing
response.redirect destfile
%>

Sure enough
when cfile = "index.html", I went to that page on the server
when cfile = "indexx.html", I went to "zipcodeerror.html" on the server.

Actually, since I have a default error404 page, this works just as well
<%
Const cfile = "indexx.html"
response.redirect cfile
%>

But in the context of going to a page for a specific postcode (sorry zipcode, my Australian-ness
showing here), it would be better to use a specific error page.

I will peruse MS Windows Script Technologies to further my knowledge of (inter alia)
filesystemobject

--
Cheers,
Trevor L.
[ Microsoft MVP - FrontPage ]
MVPS Website: http://trevorl.mvps.org/
 
Back
Top