views:

174

answers:

3

I'm wondering if it's possible to use mod rewrite along with the ErrorDocument deceleration to customize the error pages depending on what type of file is requested.

For example a non-existent html or php file is requested Apache will give nice custom HTML page.

But if a non-existent image, js, css, etc... file is requested then Apache will serve out a basic html file with only a link on it.

A good example of this behavior is Facebook. Try requesting a bogus JavaScript file, you will receive a different page then if you were to request a non-existent php file.

A: 

Use RewriteCond !-f along with a rewrite to the desired output page and a flag of R=404.

Ignacio Vazquez-Abrams
I see where you're going. The only issues is I don't want to redirect to a new URL I just want a 404 page at the requested url.
AWinter
`R` with a code outside of 3XX will do only an internal redirect. Just point it to error404.js, or error.css, or whatnot.
Ignacio Vazquez-Abrams
A: 

Ended up using a combination of both ErrorDocument and RewriteRules this works because the php page throws a 404 Not Found for me.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .*(?<!.js|.css|.ico|.txt|.bmp|.gif|.png|.jpeg|.jpg)$ /error/404.php [L]

ErrorDocument 404 /404_basic.html
AWinter
A: 

You could use a PHP script for your 404 page:

ErrorDocument 404 /error404.php

There you can analyze the URL path with PHP (see $_SERVER['REQUEST_URI']) and determine what kind of resource has been requested or is expected.

Gumbo
I was originally doing that. What I'm hoping to do is reduce the number of PHP requests to the sever.
AWinter