Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it OK to HTTP redirect images?

Is it OK to return a 301 / 302 / 303 code when returning an image resource? I have done this in the past and it seems to work. Is it good practice and is it compatible with most browsers?

like image 792
Joe Avatar asked Sep 23 '10 12:09

Joe


People also ask

Should you redirect images?

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.

Is URL redirect bad?

Redirects are not bad for SEO, but — as with so many things — only if you put them in place correctly. A bad implementation might cause all kinds of trouble, from loss of PageRank to loss of traffic. Redirecting pages is a must if you make any changes to your URLs.

Are website redirects safe?

However, you need to be sure anywhere you do redirects, they are done safely – otherwise you are putting your users in harm's way by enabling phishing attacks. Modern web-mail services are very good at spotting spam and other types of malicious messages.

How do I redirect an image to a URL?

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.


1 Answers

Yes, you can redirect images and browsers will follow redirects. But you'll generally want to keep redirection to a minimum for performance reasons, because each redirect requires a separate HTTP request, which adds server overhead and increases end-user page load time a little.

The one thing you should definitely avoid is redirecting many images on a page. This will severely slow down page load time, especially on high-latency networks (e.g. phone, China, satellite internet) where each new HTTP request takes a long time. Also, HTTP clients are limited to a small number of simultaneous HTTP connections per server hostname, so even on fast networks you'll end up with a bottleneck.

Redirecting 1 or 2 images on a page is not a big deal, however.

If you redirect images and they're cacheable, you'd ideally set an HTTP Expires header (and the appropriate Cache-Control header) for a date in the distant future, so at least on subsequent visits to the page users won't have to go through the redirect again.

If the reason you're redirecting is to conform to a new URL scheme, most web servers have an easy way to rewrite URLs on the server without having to send an actual redirect back to the client. In other words, the client may request /static/bar.jpg but the server can be configured to translate that into /media/images/bar.jpg. This URL-rewriting approach is preferable to redirection in most cases, since you can refactor where your content lives on the server without incurring the redirection overhead on the client or server side.

like image 102
Justin Grant Avatar answered Sep 19 '22 20:09

Justin Grant