tags:

views:

23

answers:

1

I've set this up successfully in IIS in the past, but i'm not sure how to do it in Apache. I want to check to see if a file exists, whether it be:

/path/to/file.php
/path/to/file.cfm
/path/to/file.html
/path/to/

If the file does not exist, I want to redirect to /404/, where I have a file that does all 404 related handling.

Lastly, when doing this in IIS, it gave me a CGI.QUERY_STRING of something like:

404;http://example.com/prettyurl

Can apache do the same?

This is what i've tried to so far, to no success. (I'm probably way off here...)

RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} -f
RewriteRule (.*)$ /404/ [R,L,NC]

Thanks..

A: 

Don't use the document_root slash..., simply do REQUEST_FILENAME -!f Exclamation mark negates the -f flag.

Mikulas Dite
hmm, so you mean: " RewriteCond %{REQUEST_FILENAME} -!f " That doesn't seem to work..
Rick
Well I'm sure this works:RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule .*$ error.php [L]
Mikulas Dite
Sweet, that seems to have done it for me. I think I still have some config issues with my Coldfusion server, but if I rewrite to an .html page it works. thanks very much Mikulas! (i'd vote "thumbs up", but apparently I don't have enough reputation points!)
Rick
On stackoverflow, simply click the green tick underneath that point count, otherwise others will see your lack of makred answers for your questions and will tend not to answer and users with same problem can identify the right answer easily.
Mikulas Dite