Rewrite only if Image don't exists with .htaccess
5,485
Try something like this.
RewriteCond %{REQUEST_FILE} !-f
RewriteRule ^(.*)$ http://site2.com/$1 [QSA,R,L]
Related videos on Youtube
Author by
Orbital
Hello, I'm Olexander, I love {coding} and I enjoy helping people. If my answers helped you, I'd appreciate it if you can +1 (upvote) my answer.. 👍😉 Thanks a bunch for visiting! 😘 Contact me
Updated on September 18, 2022Comments
-
Orbital over 1 year
How do I make RewriteCond+RewriteRule change site1.com/folder1 to site2.com/folder1, only if file in this directory don't exist. For example: site1.com/wp-content/uploads/2014/03/image.jpg
If image site1.com/wp-content/uploads/2014/03/image.jpg don't exists, than get site2.com/wp-content/uploads/2014/03/image.jpg But if image exists, don't do anything.
Update, here code what i need, thanks all for help )
Options +FollowSymLinks RewriteEngine ON RewriteCond %{REQUEST_URI} "/uploads/" RewriteCond %{REQUEST_FILENAME} .*\.(jpeg|jpg|gif|png)$ RewriteCond %{REQUEST_FILENAME} !-f RewriteRule (.+) http://site2.com/$1 [L,R=301]
-
Ladadadada about 10 yearsDo you want a solution for just the example you have given or for any image on
site1.com
?
-