-1

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]
Orbital
  • 105
  • 1
  • 4

2 Answers2

5

Try something like this.

RewriteCond %{REQUEST_FILE} !-f RewriteRule ^(.*)$ http://site2.com/$1 [QSA,R,L]

nullmem
  • 226
  • 1
  • 2
1
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
# the above ignores any url for a file that exists on the site
RewriteCond %{REQUEST_FILENAME} !-d
# the above ignores any url for a directory that exists on the site
RewriteRule ^(.*)$ http://[NEW_DOMAIN]/$1 [QSA,R,L]
# Redirect to another site and remain the same URL
marsh-wiggle
  • 2,075
  • 4
  • 26
  • 44