Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to retrieve 'bad' portion of URL in 404 trap 1

Status
Not open for further replies.

Glasgow

IS-IT--Management
Jul 30, 2001
1,669
GB
I have set up a site that redirects 404 (page not found) errors to a custom ASP page. In that page I'd like to be able to retrieve the text of the URL that the visitor provided and act upon it. I have scanned through the Request object's ServerVariables collection and experimented with many of them but have yet to find one that will return me that text.

Any suggestions?
 
You will find it as part of Request.ServerVariables("QUERY_STRING")
 
Thanks but I don't think that's any use to me as it returns only the portion of the URL that follows the question mark, if present. There is no question mark in the url I'm trying to parse.
 
Hmmmm...

I have done what you did (create a custom ASP page, and redirect 404 errors to that page), and when I browse to [ignore][/ignore], the QUERY_STRING server variable shows the following:
[ignore]404;[/ignore]

So, I get the entire URL (with a 404; tacked on at the beginning). My server is using IIS 6.0, if that matters...

So for you, the QUERY_STRING from the custom 404 page is showing a blank if there is no question mark???
 
Interesting and frustrating at the same time. I get blank if no question mark and I get whatever follows it when one is present. Not sure about server as it's a remotely hosted site.
 
If you're not sure about the server, how did you redirect 404 errors to your custom page??
 
Through a web-based control panel facility. I have no direct access to the IIS.
 
I'm at loss also; try adding the following to your custom 404 page, and see if the PATH_INFO / PATH_TRANSLATED are in fact pointing to your custom 404 page... beyond that, I'm not sure what else to suggest without having access to the server.

Code:
response.write _
	"PATH_INFO = " &        Request.ServerVariables("PATH_INFO") & "<BR>" & _      
	"PATH_TRANSLATED = " &  Request.ServerVariables("PATH_TRANSLATED") & "<BR>" & _
	"SCRIPT_NAME = " &      Request.ServerVariables("SCRIPT_NAME") & "<BR>" & _    
	"QUERY_STRING = " &     Request.ServerVariables("QUERY_STRING") & "<BR>" & _   
response.end
 
You could set up in IIS that your "404" page is something like:

Code:
[URL unfurl="true"]http://mydomain.com/errPages/404.asp[/URL]

then use the HTTP_REFERER server variable to find the page the user was just on before hitting the 404 page

Code:
response.write request.serverVariables("HTTP_REFERER")




--------

GOOGLE is a great resource to find answers to questions like "how do i..."


--------
 
Thanks for the further input. I think I've tried most if not all of these suggestions to no avail. I will double check tomorrow.

vicvirk - I had set up the 404 page much as you suggest but what I need to know is not the page the user was on - I want to know what he/she typed (which will not correspond to an existing page).

For example - they may have typed: instead of
 
guitarzan I owe you an apology. The QUERY_STRING does return the info I need. I'm not sure how I missed this. I've been testing on both local and remote machines with different results and problems. I've also occasionally been calling the error trap page explicitly (so QUERY_STRING is blank as there is no question mark and the error page itself exists). I must have got confused - duh.

Thanks.
 
We've all done that at one time or another :) glad you got it sorted.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top