Some setup:
We have some static images, publicly available. However, we want to be able to reference these images with alternative URLs in the image tag. So, for example, we have an image with a URL like:
http://server.com/images/2/1/account_number/public/assets/images/my_cool_image.jpg
And, we want to insert that into our front html as:
<img src="http://server.com/image/2/my_cool_image.jpg">
instead of
<img src="http://server.com/images/2/1/account_number/public/assets/images/my_cool_image.jpg">
One really neat solution we've come up with is to use 301 redirects. Now, our testing has rendered some pretty neat results (all current generation browsers work), but I am wondering if there are caveats to this approach that I may be missing.
EDIT: To clarify, the reason we want to use this approach is that we are also planning on using an external host to serve up resources, and we want to be able to turn this off on occasion. So, perhaps the URL in the would be
http://client.com/image/3/cool_image.jpg
in addition to the "default" way of accessing
Redirecting old image URLs to new URLs will forward ranking signals from the old images to the new ones. Using redirects is a “fantastic” way to deal with the situation, Mueller says. Avoid changing image URLs it at all possible. But, if it has to be done, make sure redirects are in place.
Redirects are used for various purposes such as the relocation of a website to a new domain, temporarily forwarding traffic during server maintenance, merging duplicate content, and to relocate website visitors from old, out-of-date content pieces to new pages.
To use image as a link in HTML, use the <img> tag as well as the <a> tag with the href attribute. The <img> tag is for using an image in a web page and the <a> tag is for adding a link. Under the image tag src attribute, add the URL of the image.
Just wrap your image tag insdie a tag, like this: <a href="https://where-you-want-to-redirect"> <img href="your-image-src"> </a>
Another technique that doesn't require a server round-trip is to use your HTTP server's equivalent of a "rewrite engine". This allows you to specify, in the server configuration, that requests for one URL should be satisfied by sending the results for some other URL instead. This is more efficient than telling the browser to "no, go look over there".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With