Search code examples
.htaccesshttp-redirectisapi-rewrite

.htaccess Redirect in case of 404


I have this line of .htaccess This line is used to get images from another server.

RewriteRule ^resources/fabricantes(.*)$ http://mysecondserver.com/arq/pictures/fab$1

than, if I have the url: http://myserver.com/resources/fabricantes/fab_1.jpg this image will be get from: http://mysecondserver.com/arq/pictures/fab/fab_1.jpg

The Problem: In some cases, the image doesn't exists on mysecondserver.com, how can I redirect to a "image unavailable" image in this cases?


Solution

  • First think you need to understand that this rule can only work from mysecondserver.com host not from server.com.

    On mysecondserver.com place this .htaccess in /arq/pictures/.htaccess:

    RewriteEngine On
    RewriteBase /arq/pictures/
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ no-image.jpg [L]