Reputation: 36937
I used to have a site up and running on a domain of mine, that I have since taken down. However in that site I had a handful of specific images that I had either shared with other sites.
Its been a while since I visited the logs of that domain, and I realize that there is about 2 dozen images coming up as 404, and I recognize them as the images shared. What I want to do is put those images on another domain of mine, and have any requests coming for those images get rewritten with the other domains url where the images now reside.
Is this possible, to specify images on a one to one basis and have them point to there counter parts on the other domain? I've seen it done where people are being not so selective but nothing in terms of what I would like to do.
Upvotes: 1
Views: 2035
Reputation: 6968
Yes, you can do that with .htaccess.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Options +FollowSymLinks
RewriteRule ^img/path/to/file1.jpg$ http://newdomain.com/new/path/to/file1.jpg [L,R=301]
RewriteRule ^img/path/to/file2.jpg$ http://newdomain.com/other/new/path/to/file2.jpg [L,R=301]
RewriteRule ^img/path/to/(file3.jpg|file4.jpg)$ http://newdomain.com/typical/new/path/to/$1 [L,R=301]
</IfModule>
Considering http://olddomain.com/img/path/to/file1.jpg
is one of the image files and the .htaccess is in the document root of olddomain.com
, this should do the job. If you can't match the old and new file names against some regular expressions you'd need to have a line with RewriteRule
for each missing image.
Upvotes: 5