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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error 404 template with query string?

Status
Not open for further replies.

lucidtech

IS-IT--Management
Jan 17, 2005
267
US
I have a custom 404 error document setup in my .htaccess file. I was wondering, is there a way to pass the original url typed in (the url that the browser attempted to visit but was not found) to the template that is loaded?

Meaning, if I type in in my browser and that page doesn't exist, then the default error template is loaded passing THAT address in a variable to the template (like
 
Hi

lucidtech said:
is there a way to pass the original url typed in
It is already available. Unless a redirection happens before, the error handler will still have the original request in the [tt]REQUEST_URI[/tt] environment variable ( or something equivalent if you use some framework ). If handled internally ( in fact not redirected, just rewritten ) also a set of variables with names prefixed with [tt]REDIRECT_[/tt] are set to provide details about the circumstances.

However if your [tt]ErrorDocument[/tt] points to a static file, those environment variables will be of no use.

Regarding your syntax with the query string, there is no way to do it like that, as far as I know.


Feherke.
 
Thank you for your reply. I tested this with PHP and it worked, but I need this to work on my railo server, which is running Tomcat. Seems as though the request environment variable is being lost in the process... any ideas?
 
Hi

Never heard about railo before and my relation with Tomcat was not a close one.

If your configuration looks like [tt]ErrorDocument 404 /just/a/path[/tt], then I would say, it should work with that railo too.

If your configuration looks like [tt]ErrorDocument 404 [ignore][/ignore][/tt], then I would change the handler to a PHP script which redirects to the railo thing using [tt]header()[/tt], passing the [tt]REQUEST_URI[/tt] in the query string.

Note that redirecting on a 404 error is a bad idea as it confuses the crawlers.


Feherke.
 
Okay, this is for anyone who searches for a solution with this same problem : Apache server with Railo & Tomcat on a linux box which displays empty cgi variables on a custom 404 error page. Here is what I did (reference to this post, all credit due to the author, but I'm posting it here too with simplified instructions
Added the followings to my httpd.conf file, in the <IfModule mod_jk.c> section :

JkEnvVar REDIRECT_URL ""
JkEnvVar REDIRECT_REMOTE_HOST ""
JkEnvVar REDIRECT_PATH ""
JkEnvVar REDIRECT_QUERY_STRING ""
JkEnvVar REDIRECT_HTTP_ACCEPT ""
JkEnvVar REDIRECT_HTTP_USER_AGENT ""
JkEnvVar REDIRECT_REMOTE_ADDR ""
JkEnvVar REDIRECT_SERVER_NAME ""
JkEnvVar REDIRECT_SERVER_PORT ""
JkEnvVar REDIRECT_SERVER_SOFTWARE ""

Restarted my server, then set a variable via CFML using this :

<cfset checkName = getPageContext().getRequest().getOriginalRequest().getAttribute('REDIRECT_URL')>

This worked perfectly for, and I hope someday someone pulling their hair out for hours finds this post and it helps them too. Thank you fo ryour help feherke and to the author of the link I posted. Finally I can have custom urls for user profiles.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top