Redirecting requests dynamically?

  • Truce
  • Guru
  • Guru
  • No Avatar
  • Joined: Apr 25, 2004
  • Posts: 1477
  • Loc: Washington DC
  • Status: Offline

Post October 26th, 2005, 1:37 pm

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
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post October 26th, 2005, 1:37 pm

  • Truce
  • Guru
  • Guru
  • No Avatar
  • Joined: Apr 25, 2004
  • Posts: 1477
  • Loc: Washington DC
  • Status: Offline

Post October 26th, 2005, 1:40 pm

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
  • No Avatar
  • Joined: May 15, 2004
  • Posts: 141
  • Status: Offline

Post October 27th, 2005, 8:50 am

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
  • No Avatar
  • Joined: Apr 25, 2004
  • Posts: 1477
  • Loc: Washington DC
  • Status: Offline

Post October 27th, 2005, 9:57 am

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
  • No Avatar
  • Joined: Apr 25, 2004
  • Posts: 1477
  • Loc: Washington DC
  • Status: Offline

Post October 28th, 2005, 10:56 am

Bump

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 80 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
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.