是否可以使用 HTTP 重定向非 HTML 文件?和链接重定向?

发布于 2024-08-25 18:24:50 字数 527 浏览 8 评论 0原文

我一直在考虑一种巧妙的负载平衡方法,需要的一件事是能够从多个位置在 HTML 页面上加载图像,而无需重写 URL(在每次加载时)

所以我需要能够要做的就是拥有一个 URL,即“静态”URL。例如 http://example.com/myimage.png 但该图像实际上并不包含在 example.com 中。因此,example.com 会执行 302 或 301 或 307 HTTP 响应,以导致重定向到 2.example.com。在这种情况下,浏览器如何处理图像?另外,浏览器如何处理多个重定向,例如如果 2.example.com 也不包含它并且它转到 3.example.com ? (请注意,我问这个问题是因为除了 HTML 页面之外,我从未在任何其他页面上见过 301 重定向)

此外,最好使用哪种状态代码。 301 意味着“永久移动”,这个“移动”不是永久的,所以我不希望它被缓存。我应该使用307吗?搜索引擎和现代浏览器支持吗?

I have been thinking about a neat way of load balancing and one thing that would be required is to be capable of loading an image on an HTML page from multiple locations without rewriting the URL(on each load)

So what I need to be able to do is have one URL which is the "static" URL. Such as http://example.com/myimage.png The image is not actually contained in example.com though. So example.com does a either a 302 or 301 or 307 HTTP response to cause a redirect to 2.example.com. How do browsers handle this with images like in this situation? Also, how do browsers handle multiple redirections for instance if 2.example.com also didn't contain it and it went to 3.example.com ? (Note, I am asking this because I've never seen a 301 redirect on anything but an HTML page)

Also, which status code would be best to use. 301 means "moved permanently" which this "move" isn't permanent so I don't want it cached. Should I use 307? Is that supported by search engines and modern browsers?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

荒路情人 2024-09-01 18:24:50

重定向是一个 HTTP 概念,适用于可以通过 HTTP 传送的任何资源,而不仅仅是 HTML。链接重定向和非 HTML 重定向在大多数现代浏览器中都能正常工作。

如果您想要临时重定向,请使用 302,除非您也想重定向 POST 和 PUT。问题是,大多数实现都会在 POST 或 PUT 收到 302 之后发出 GET 来获取新资源地址。

请注意,303 和 307 是 HTTP 1.1 特定的。

Redirect is an HTTP concept and applies to any resource that can be delivered over HTTP, not only HTML. Chaining redirects and non-HTML redirects work just fine in most modern browsers.

If you want temporary redirect, use 302, unless you want to redirect POST and PUTs as well. The problem is that most implementations will issue GET for the new resource address after POST or PUT that got 302.

Note that 303 and 307 are HTTP 1.1 specific.

葵雨 2024-09-01 18:24:50

我建议不要这样进行负载平衡。负载平衡不是 3xx 响应的目的。

HTTP 协议具有缓存功能,有助于减少服务器负载。还有用于负载平衡的服务器技术。这些技术发展得好将会更加稳定和可重用。

I would advise against load balancing like this. Load balancing is not what 3xx responses are intended for.

The HTTP protocol has capabilities for caching which can help with reducing server load. There are also server technologies for load balancing. These technologies are well developed will be more stable and reusable.

深海夜未眠 2024-09-01 18:24:50

正如 Benedict C 所说,我认为你找错了对象。

如果要做负载均衡,那就做负载均衡。循环 DNS 是最简单的方法(并且在许多方面比更昂贵的解决方案更有效)。如果您必须尝试在具有不同 FQDN 的服务器之间实现负载平衡,请在 javascript 中生成 URL 客户端。

您帖子的剩余部分适用于有关重定向的其他问题。有很多关于 SEO 的不好的建议。 Google 拥有大约 92% 的全球市场,并发布了有关如何抓取和排名网站的非常详细的规范。您域内的重定向不应影响您在任何有能力的搜索引擎中的排名。在域外重定向只会提高目标的排名。

是的,浏览器对单个请求所遵循的重定向数量实施限制 - 但它因浏览器而异。

As Benedict C says, I think you're barking up the wrong tree.

If you want to do load-balancing, then do load balancing. Round robin DNS is the simplest method (and is more effective in a number of regards than more expensive solutions). If you must try to load balance across servers with different FQDNs, then generate the URL client-side in javascript.

The remnants of your post are applicable to other questions about redirection. There's a lot of bad advice published about SEO. Google has approx 92% of the world market and publish quite detailled specs about how they spider and rank sites. Redirection within your domain should not affect your rankings in any competent search engine. Redirection outside your domain will only improve the ranking of the target.

Yes, browsers implement a limit on the number of redirections followed for a single request - but it varies by browser.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文