.htaccess - "conditional" custom 404 page?

Soldato
Joined
12 Dec 2006
Posts
3,421
Location
Worthing, West Sussex
Hey,

I have my "ErrorDocument 404 /404.html" for people who look for stuff that doesn't exist...

But I'm looking for something (maybe rewritecond) which goes before that to help me say;

If looking for .gif and it doesn't exist
-> give 404.jpg
If looking for .jpg and it doesn't exist
-> give 404.jpg
If looking for .png and it doesn't exist
-> give 404.jpg
If looking for .bmp and it doesn't exist
-> give 404.jpg

I'm pretty sure that's the structure I'm going to have to use, and rewritecond is probably what I'm going to need to do it with...

But that's about it. I can't muster up all the info I need using Google, so I think I need some help from real people! How do I actually do this?
 
I'm sure theres a more concise way but this should work :

Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} \.jpg$ [OR]
RewriteCond %{REQUEST_FILENAME} \.bmp$ [OR]
RewriteCond %{REQUEST_FILENAME} \.gif$ [OR]
RewriteCond %{REQUEST_FILENAME} \.png$
RewriteRule . /404.jpg [L]
ErrorDocument 404 /404.html

PS your sig is scary
 
Ahh, muchos thankos! Very appreciated :D shortened it a little by doing this:

Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} \.(jpg|bmp|gif|png)$
RewriteRule . /404.jpg [L]
ErrorDocument 404 /404.html
Glad you like the sig :p I think it's someone on this forum's dog...
 
Back
Top Bottom