I have an app in node.js and I want to make a route that redirects all hotlinks to images to the article/URL the image was used on.
But since all the images are stored in /public/img
directory and article URLs are generated programmatically, how do I tie down each image to its article? ..in a way that would allow me to redirects all hotlinks to the images to the article/URL the image was used on?
For example,
My article is
http://www.site.com/blog/archives/2013/article-slug/
and it uses the image
http://www.site.com/img/that-image.jpg
because all images are stored in /public/img
dir.
Then if someone hotlinks to the image http://www.site.com/img/that-image.jpg
, how do I redirect to the article it was used in http://www.site.com/blog/archives/2013/article-slug/
? (I can check whether it was hotlinked probably by checking the referrer
header)
But how do I store the relevant information about which image is used in which article, and how do I use that information to do the redirect?