Forum Moderators: open
You can retrieve the requesting form's contents via intrinsic ASP objects. The querystring does not have to be visible in the URL bar.
I believe this is common to all server side scripting. It's all a matter of how you designate the HTML <FORM>.
Any ideas
As an example, lets say you have a dynamically built page to display news articles. You have a link to an article with a unique identifier in your database as 23. So, your link might look something like /news/detail_page.asp?articleID=23. Makes sense so far. Well here is where it gets interesting. Instead of naming the link /news/detail_page.asp?articleID=23, why not name it /news/23.
When you click on the link named /news/23, you will naturally get a "404 page not found" error. The trick is to build a custom 404 page. In my case I created a directory called "errors" with a file name 404.asp and then pointed my 404 errors to this page. On the 404 page, the first thing that I need to do is parse out the information that is important to me from the link that I clicked, so the first thing that I need to get is the original string and make it a variable...
strOrigURL = lcase(request.servervariables("QUERY_STRING") )
The next thing that I need to determine is what article I am trying to display. To do this, I can use something like the following:
Dim Selection
if instr(strOrigURL,"/news/") >0 then
Selection = "news"
intStart = instr(strOrigURL,"/news/") + 6
intNews = replace(mid(strOrigURL,intStart),"/","")
end if
Now I have parsed out the "23" and I can write code in my 404.asp page to display the article directly in the 404 page.
By using elseif statements, you can parse out multiple possibilities of strings. for example you could have an original url of /employees/99.
You can then use case select statements to created recordsets based on the original string. i.e. news or employees.
In my case, I used case select statements to call include files to build the page based on the parsed information.
The search engine will crawl this 404 page with no problem and it works extremely fast.
In theory, using this technique, you could have a site with thousands of pages that only has one physical page in the site (404.asp) and a large database.
I know that it seems confusing, but play with it. When the light comes on, you will laugh at how easy it really is.
I tried to do similar things with php & apache.
.htaccess
ErrorDocument 404 /404.php
404.php -- doing the work.
This is on a very standard (but good) hosting package - I have control over .htaccess on a directory basis.
And its seems to work fine ! Looks like I'm going to have a very spiderable site soon :)
Thanks oogachaka
ps. Welcome to Webmaster world ;)
(cool I've finally got to say it)
I understand the concept and it makes sence as well as sounding like a simple solution, I'll give it a go.
Cheers
No 404 Not Found will be sent? Or do you change the header information?
By the way, I use this method for all of the development work that I do now.
Gethan, good to hear that you are doing this with php. Same principle, you probably just use about half of the lines of code that I use in ASP. I have done some simple work in PHP, and I like the language. Maybe someday I will try to explore it more. If only days had 36 hours in them instead of 24.
Happy Coding!
Some browsers still get the 404 and display a 404 default page unless the headers are changed.... (spotted by Ulrike and ignored by me earlier ;))
php: Header("HTTP/1.0: 200 OK\n");
asp: response.status("200 OK") -- from another thread I'm no asp guru.
As for logging I have the same problem on my hosting package all are logged as 404s .. but at home on Apache Linux also the Header command fixes the server logs also. Very strange.
So I'm trying to work a way around it, one method (theory only) is to actually create the files on request as just <?include "404.php";?> assuming the html handlers are set to phpise any file in that directory.
A more elegant solution would be much appreciated ;)