Reputation: 670
i want to serve static (*.png) files with apache2 from /var/www/html/tiles/. if a png file is not available, it returns a 404 (correctly). what do i have to do to make it redirect to a fallback.png if the requested file is not present?
i am currently using the default apache config with this default site:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
#FallbackResource /fallback.png
<Directory /var/www/html>
Options +FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
what i tried to add is:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
#FallbackResource /fallback.png
<Directory /var/www/html>
Options +FollowSymLinks
AllowOverride All
</Directory>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(png)$ /tiles/fallback.png [L]
</VirtualHost>
but the effect is, that now every *.png request gets reroutet to fallback.png. it should only happen if the requested is not available.
What can i do?
Thanks a lot!
Upvotes: 0
Views: 14
Reputation: 670
Ok, found the problem:
it needs to be:
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/$1 !-f
RewriteRule ^(.+\.png)$ /tiles/fallback.png [L]
Upvotes: 0