How to check if file exists in Apache

Posted by Rick on Stack Overflow See other posts from Stack Overflow or by Rick
Published on 2010-05-25T18:56:08Z Indexed on 2010/05/25 19:01 UTC
Read the original article Hit count: 186

Filed under:
|

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..

© Stack Overflow or respective owner

Related posts about apache

Related posts about iis