Forum Moderators: open
"h*tp://www.example.com/dynamicvalue" without using URL rewrite?
[webmasterworld.com ]
I used the excellent suggestion by "plumsauce" and have configured my IIS properly for the 404 handling, and have written the ASP code for my default.asp page (which is the home page), and everything is working just fine - except for one thing, which is that I'm seeing an ugly mangled up address in the address bar of my browser. What have I done wrong, or what have I simply missed doing, that needs to be done to keep the address as it was typed in?
Confession time: I'm NOT an ASP programmer, nor am I even an IIS administrator kind of guy, but am an old C/C++ and Perl coder, so I know there could be something really simple I'm not doing that I just don't know about.
Here is the general method that "plumsauce" described:
Set default.asp as the default 404 handler for the root directory only, using URL and not FILE as the type. See the management console for this.When the server sees:
h*tp://www.example.com/mattglet
it will execute:
default.asp?404;h*tp://www.example.com/mattglet
parse the query variable in default.asp using a regular expression to extract the mattglet part and carry on.
I also read that the Google spider in recent months has been coded to be able to handle simple "depths" of varibles as represented by my example. But I can assure you that the Google spider has not put the website I'm working on in its search results. Therefore, from my research I realized that I wanted to be able to have something like
replace what we were using. So after configuring the IIS 404 handler entry and writing a bunch of ASP code that I added to the default.asp page you can now enter
and the default.asp page will generate the "page 3" page just as when you enter the previous form of
However, my problem now is that up in the address box of the browser it shows
which as you can see just looks ridiculous!
So for all you ASP coders out there, I'm asking for: HELP!
Below is the default.asp page that I have written. Besides this slight, but ugly, flaw that I have just mentioned, this works great for generating the pages without using any kind of URL rewrite ISAPI modules. So in addition to helping me out taking this code the final step, here is a working example of just how to do this kind of thing. (Please don't snicker, too much, at the code - as I already mentioned I don't even use ASP, this is actually my first ASP-coded page, so if you see odd ways of doing things it's probably from my C/C++ and Perl ways of thinking and unfamiliarity with ASP.) Feel free to ask me additional questions for clarification of details. By the way, I'm running on IIS 5 on Windows Server 2000.
Regards,
Todd Greene
Active River Computer Solutions, Inc.
Charlotte, Michigan
------------------------------------------------
<%@LANGUAGE="VBSCRIPT"%>
<%
option explicit
dim conn
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "C:\www\website.com\data\wspages.mdb"
%>
<%
dim pageid
dim flagbad
dim strchk
dim lenstrchk
dim relpath
flagbad=true
relpath=request.querystring
strchk="404;http://www.website.com/"
lenstrchk=len(strchk)
if (left(relpath,3)<>"404") then
flagbad=false
pageid=request.querystring("page")
if pageid="" then pageid="1" end if
else
if (len(relpath)>lenstrchk) then
if (left(relpath,lenstrchk)=strchk) then
relpath=replace(relpath,strchk,"")
strchk="default.asp/"
lenstrchk=len(strchk)
if (len(relpath)>lenstrchk) then
if (left(relpath,lenstrchk)=strchk) then
relpath=replace(relpath,strchk,"")
dim arr
arr=split(relpath,"/")
if (ubound(arr)+1=2) then
if ((arr(0)="page") and (isnumeric(arr(1)))) then
dim rs
dim cntpgs
dim pgno
set rs=conn.execute("SELECT count(*) AS cntrec FROM content")
cntpgs=cint(rs("cntrec"))
pgno=cint(arr(1))
if ((0<=pgno) and (pgno<=cntpgs)) then
flagbad=false
pageid=arr(1)
end if
end if
end if
end if
end if
end if
end if
end if
if (flagbad) then %>
<!--#include file="top.asp"-->
<!--#include file="main_menu.asp"-->
<!--#include file="page404.html"-->
<!--#include file="bottom.asp"-->
<% else %>
<!--#include file="top.asp"-->
<!--#include file="main_menu.asp"-->
<%
dim SQL
dim pagedisplay
dim filename
SQL="SELECT content FROM content WHERE page = " & pageid
set pagedisplay=conn.execute(SQL)
filename = pagedisplay("content")
conn.Close
if filename <> "" then
filename = "/data/" & filename
dim objFSO
dim objText
set objFSO = Server.CreateObject("Scripting.FileSystemObject")
set objText = objFSO.OpenTextFile(Server.MapPath(filename),1) ' MapPath gets physical path for the file
response.write(objText.ReadAll)
objText.Close
set objText = Nothing
set objFSO = Nothing
end if
%>
<!--#include file="bottom.asp"-->
<% end if %>
In CF I do this simply by calling page.cfm/a/1 (instead of page.cfm?a=1). IIS will still call page.cfm without bothering about the stuff after it.
I can then run a loop, gathering everything after the pagename, which retrieves the pairs of values. (a/1/b/2 become a/1 - b/2). I then create a variable whose name is the first value, and whose content is the second value.
Hey presto!
First of all, I should mention that this is now all a moot point for me. I realized yesterday around lunch time that trying to use the "404 handler, with Server.Transfer" method was sinking me into a black hole. Don't get me wrong, I think it's a neat little trick, but I needed to pass along just a little bit of information to the ASP page invoked by the Server.Transfer, and I started having to dig into Session variables and other crap and then I had to start worrying out cookies and etc. and etc. and I realized "Okay, enough is enough, why am I spending any more time on this?"
So I have to admit that I bit the bullet and went to [isapirewrite.com ] (no, I'm not a Helicon salesman!) and downloaded their ISAPI_Rewrite dll (the free Lite version; note that they actually give you a nice Windows install file that does all the nasty setup work for you of the registry settings and IIS configuration). If anyone has any questions about this, feel free to ask further. But for me it's working like a charm (though I'm getting the boss to spring for the $69.00 for the full version).
By the way, Sanenet, if you check out the discussion thread from a year ago that I gave the link to, you'll see in that discussion that one member stated the same thing you did about 404 headers getting sent to the spider, and you'll see that that was disputed. I cannot address that myself definitely, because I abandoned that approach before I got as far as checking out the HTTP headers to verify that one way or the other. But realize that if I had found that a 404 header was indeed what was being sent out, then in the ASP VBScript there is a command I could have used to change the header to 200. Just so you know.
<snip>
[edited by: Xoc at 9:29 am (utc) on Feb. 19, 2005]
[edit reason] No sigs [/edit]