Tuesday, May 10, 2005

Apache 404 / CGI Weirdness....

OK, this is a strange one. I've been scratching my head for a couple of hours over this, and I just can't see what I've missed - can some good samaritan see the glaringly obvious and point it out to me?

I have a system that needs the same code deployed across 1 Win2K3 box, and 1 Redhat box. Same code on each.

In this system, I use a custom 404 to allow the site owner to specify an arbitrary "short link" for a CMS page.

e.g. Owner of site X creates a page with the title "About Us", and gives it a short link of "about".
He/she can then use the url "http://(site domain)/about" to access that page.

Simple enough, shouldn't be anything complicated there, right? I just have a custom 404 that uses CGI variables to parse the requested URL and redirect to the appropriate page, right?

Well....

It works fine on the Windows box, but for some reason, Apache is not passing on the requested URL to the 404 page. I've dumped the CGI scope in the 404 page, and I get nothing mentioning the requested URL. Nada. Zip. Bugger all.

QUERY_STRING is empty, and although the Apache documentation says it will provide a whole load of REDIRECT_xxxx variables, I don't get any of them in CFMX.

I freely admit I'm not an Apache expert, so if anyone out there IS, and they know what I'm missing - can you help?

Relevant versions:
Apache 2.0.46
Red Hat Enterprise (9)
CFMX Standard 6.1, updater 3

UPDATE 8th August 2005: FIXED!

I discovered that although a cfdump of the CGI scope doesn't show the existence of the REDIRECT_URL key, if you just test for existence with StructKeyExists( CGI.REDIRECT_URL ) it *is* actually there, and you can use it.

....which raises some curious questions about how cfdump is working under the hood....

5 comments:

Phillip Harrington said...

I believe you want to grab REDIRECT_URL. Check out:
http://httpd.apache.org/docs/custom-error.html

Phillip Harrington said...

Ooops. You tried that. Sorry. Um, hmm. Let me think it over. Have you tried one of the lists? I've never tried an Apache/CFMX 404 now that I think about it.

Alistair Davidson said...

FIXED!

See the update in the main post for details

phenotypical said...

Thank God for bloggers. I had forgotten the name of this CGI variable, but knew it was in there somewhere. Now, how to get the query_string (from the 404)

phenotypical said...

hey, whodathunkit: cgi.redirect_query_string!