Redirecting requests dynamically?

  • Truce
  • Guru
  • Guru
  • Truce
  • Posts: 1477
  • Loc: Washington DC

Post 3+ Months Ago

I have a rather particular situation. I have a bunch of images in a directory on one server that are being hotlinked from various sites. I will be moving these images to a different site, but they will have the same names. I don't want everyone's links to become broken, so I would like to somehow redirect a request for one of these images to the same image on another site.


A little more graphical explanation:

Browser -> Requests mydomain.com/images/150.jpg
Server -> Redirects request to newsite.com/linkimages/150.jpg
User -> Sees newsite.com/linkimages/150.jpg instead of a broken image.


PLEASE HELP ASAP. I really need this....


Thanks everyone.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Truce
  • Guru
  • Guru
  • Truce
  • Posts: 1477
  • Loc: Washington DC

Post 3+ Months Ago

I already had an idea, but it is sketchy and I don't know if it would work.....but here it is:

Setting 404 file in htaccess to point to 404.php on mydomain.com

404.php uses php code like this pseudocode:

if (is image($referrer)) then
redirect to newsite.com/somepath/$referrer
else
echo "404 error"
endif

Anybody have a better idea?
  • harryhood
  • Graduate
  • Graduate
  • harryhood
  • Posts: 141

Post 3+ Months Ago

Why not use RedirectMatch in your .htaccess file?


RedirectMatch permanent /folder/image1.gif http://www.newserver.com/folder/image1.gif
RedirectMatch permanent /folder/image2.gif http://www.newserver.com/folder/image2.gif
  • Truce
  • Guru
  • Guru
  • Truce
  • Posts: 1477
  • Loc: Washington DC

Post 3+ Months Ago

That's what I was lookin' for! Thanks a bunch! I know about this much [ ] about how to use htaccess....lmao.


Do you know of a way to make that dynamic though? I would hate to have to go through all of the images manually....there are about 600-1000.....

...maybe something with regex's or something? I would hate to have to make PHP just list through all of them and build them into a file...it would be a rather large htaccess file!
  • Truce
  • Guru
  • Guru
  • Truce
  • Posts: 1477
  • Loc: Washington DC

Post 3+ Months Ago

Bump

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 13 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.