Forum Moderators: phranque

Message Too Old, No Replies

htaccess and 404 pages

         

notbob

12:26 am on Oct 1, 2003 (gmt 0)

10+ Year Member



I'm trying to add the below 404 redirect code to my htaccess file so that if someone types a url that doesn't exist, they get redirected to a cgi script.

As an example, if someone types in [someurl.com...] and that page didn't exist, they would go to [someurl.com...]

I'm not having a lot of luck in getting it to work and was hoping someone could assist.

This is the line I've added to my htaccess file

ErrorDocument 404 <!--# include virtual="http://www.url.com/beta/page.cgi?&&HTTP_REFERER&&"-->

Thanks

ga_ga

1:23 am on Oct 1, 2003 (gmt 0)

10+ Year Member



This is completely off the top of my head & might be a lead up the garden path, so if it doesn't seem to work, don't spend too much time on it..

Instead of trying to directly place a server-side include directive in your .htaccess, could you simply specify one script without a query string..

ErrorDocument 404 /beta/page.cgi

Then, inside page.cgi, get the filename the user entered from an environment variable: either,

$ENV{'REQUEST_URI'}

or

$ENV{'HTTP_REFERER'}

(not quite sure which..)

Posting this because I recall using one of those 2 environment variables in a logger once, and remember looking in my logfile and not recognising a bunch of filenames.. misspellings, old links etc.

Hope it helps, as I say, if it doesn't seem to don't spend more than a couple of minutes on it, I might be misleading you ;-)

jdMorgan

1:42 am on Oct 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



notbob,

I suggest you add the SSI to your custom 404 page, not to your .htaccess file. .htaccess files are parsed for SSI. You will also need to name your custom 404 page with a .shtml extension, use Apache's mod_includes XBitHack directive, or use the AddType directive to tell Apache to parse your 404 page for SSI.

Jim