Forum Moderators: phranque
ErrorDocument 403 /error403.php
ErrorDocument 404 /error404.php
ErrorDocument 500 /error500.php
<FilesMatch !"\.(jpg|jpeg|gif|png)$">
ErrorDocument 403 /error403.php
ErrorDocument 404 /error404.php
ErrorDocument 500 /error500.php
</FilesMatch>
ErrorDocument 403 /error403.php
ErrorDocument 404 /error404.php
ErrorDocument 500 /error500.php
#
<FilesMatch "\.(gif|jpe?g|png|ico)$">
ErrorDocument 403 /small-image-or-blank-file.gif
ErrorDocument 404 /small-image-or-blank-file.gif
ErrorDocument 500 /small-image-or-blank-file.gif
</FilesMatch>
ErrorDocument 404 "No such image
RewriteEngine On
ErrorDocument 404 /error.php
<FilesMatch "\.(gif|jpe?g|png|ico)$">
ErrorDocument 404 /image.php
</FilesMatch>
RewriteCond %{REQUEST_URI} \.(gif|jpe?g|png|ico)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ default [R=404,L]
RewriteCond %{REQUEST_URI} 123 [NC]
RewriteRule ^(.*)$ index.php [QSA,L]
# NOT USED!:
# ErrorDocument 404 /error.php
# Images
RewriteCond %{REQUEST_URI} \.(gif|jpe?g|png|ico)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ default [R=404,L]
# Other files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ error.php [QSA]
# Declare default 404 error document
ErrorDocument 404 /error404.php
#
# Override default 404 error document for missing-image requests
<FilesMatch "\.(gif|jpe?g|png|ico)$">
ErrorDocument 404 /small-image-or-blank-file.gif
</FilesMatch>
#
# Rewrite all non-image requests containing "123" to index.php
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|ico)$ [NC]
RewriteRule 123 index.php [L]
Also, the problem with what you suggest is that for every following RewriteRules (let's say I have 20 of them) I'll have to add "RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|ico)$ [NC]" too, right?
# Declare default 404 error document
ErrorDocument 404 /error.php
# Override default 404 error document for missing-image requests
<FilesMatch "\.(gif|jpe?g|png|ico)$">
ErrorDocument 404 /image.php
</FilesMatch>
But, as I say, I would like a way to not have to deal with the images in a RewriteCond for every RewriteRule I make.
If I call "/doesntexist.gif" it works: /image.php is called. But if I call "/test/doesntexist.gif" it's /error.php that is called! Why?!?
<?php
file_put_contents("C:\\testApache.txt", time() . ' - ERROR - ' . $_SERVER['REQUEST_URI']);
--------- <?php
file_put_contents("C:\\testApache.txt", time() . ' - IMAGE - ' . $_SERVER['REQUEST_URI']);
---------
1286036207 - IMAGE - /doesntexist.gif
---------
1286036121 - ERROR - /test/doesntexist.gif
---------