Forum Moderators: open

Message Too Old, No Replies

http://www.website.com/default.asp/page/3

without using URL rewrite?

         

greeneto

8:23 pm on Feb 15, 2005 (gmt 0)

10+ Year Member



Hi everyone - I just signed up, this is my very first post. I'm posting in reference to the following topic that was discussed a little over a year ago here in this forum:

"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.


Now let me mention what my own motivation was for this. A couple of years ago someone coded these web pages (no, it wasn't me!). I was hired a few months ago. Very recently I realize that the company's website was not showing up on searches at search sites like Google. Doing a little research I soon learned that the search spiders almost totally avoid spidering pages that involve queries of the form

h*tp://www.website.com/default.asp?page=3

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

h*tp://www.website.com/default.asp/page/3

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

h*tp://www.website.com/default.asp/page/3

and the default.asp page will generate the "page 3" page just as when you enter the previous form of

h*tp://www.website.com/default.asp?page=3

However, my problem now is that up in the address box of the browser it shows

ht*p://www.website.com/default.asp?404;http://www.website.com/default.asp/page/3

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 %>

greeneto

8:29 pm on Feb 15, 2005 (gmt 0)

10+ Year Member


Well, sorry all about the loss of indents in the code. I use tabs in the left margins of my code for indenting, and i used the [code]{data}[/code] tags, but my indenting was lost. Just realize that there a lot of nested ifs in the code. — Todd

mattglet

1:04 pm on Feb 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think this page [webmasterworld.com] has what you're talking about.

Sanenet

1:26 pm on Feb 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Mind you, if you're using the 404 page as a page loader it still won't show up in google, because everytime Googlebot visits that page it gets a 404 header.

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!

greeneto

4:43 pm on Feb 17, 2005 (gmt 0)

10+ Year Member



Hi guys. Thanks for responding.

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]