使用HTTP 301的永久重定向

The very latest version of DasBlog uses a 301 Permanent Redirect to send aggregators to my feed's new location at FeedBurner. Because it's a 301, most aggregators automatically update their data with a new location and don't bother asking for the original one again.

DasBlog的最新版本使用301永久重定向将聚合发送到Feed的新位置FeedBurner 。 因为它是301,所以大多数聚合器会自动用一个新位置更新其数据,而不必费心再询问原始位置。

Here's how to do a hardcoded 301 redirect within ASP.NET:

以下是在ASP.NET中执行硬编码301重定向的方法:

response.StatusCode = 301;
response.Status = "301 Moved Permanently";
response.RedirectLocation = "http://www.hanselman.com/blog";
response.End();

response.StatusCode = 301; response.Status =“ 301永久移动”; response.RedirectLocation =“ http://www.hanselman.com/blog”; response.End();

You can also do this, which I see a lot while looking at the bathroom wall of code folks call Google Groups:

您也可以执行此操作,当我看到代码人们称之为Google网上论坛的洗手间时,我会看到很多东西:

Response.AddHeader("Location","http://www.hanselman.com/blog");

Response.AddHeader(“ Location”,“ http://www.hanselman.com/blog”);

They pretty much do the same thing, but color me reactionary, I like to use the APIs available just for cleanliness's sake.

他们几乎都做同样的事情,但是让我反感,我喜欢使用仅出于清洁目的的可用API。

Of course this is a redirect, not an URL rewrite. Redirect's go all the way back to the requester and provide a hint on where to go next, while rewrites leave the requested the URL the same and tell the web server that something else was requested.

当然,这是重定向,而不是URL重写。 重定向一路返回给请求者,并提供下一步提示,而重写使请求的URL保持不变,并告诉Web服务器其他请求。

DasBlog has a lovely rewriting HttpModule that you're welcome to use. Erv Walter extended it and added support for redirecting URLs as well as fixing host names. These things are particularly useful if you do not have direct access to your web server's administrative console.

DasBlog有一个很好的重写HttpModule,欢迎您使用。 Erv Walter对其进行了扩展,并增加了对重定向URL和固定主机名的支持。 如果您无权直接访问Web服务器的管理控制台,则这些功能特别有用。

Fritz Onion, my hero but a man I've never met, also has a great redirecting module that's very elegant and coincidentally uses Craig Andera's "Only Configuration Section Handler You'll Ever Need" which is a fantastically snazzy chunk of code that I just can't seem to get folks here at work to latch onto.

弗里茨·洋葱( Fritz Onion )是我的英雄,但我从未见过这个人,它还具有出色的重定向模块,该模块非常优雅,同时使用了克雷格·安德拉(Craig Andera)的“您将永远需要的唯一配置节处理程序”,这是我刚才所说的令人眼花sn乱的代码块似乎无法吸引人们来这里工作。

Whichever one of these models you use, or if you write the redirect yourself, remember the "principle of least surprise."

无论使用哪种模型,或者如果您自己编写重定向,请记住“最不惊奇的原则”。

If I type in the URL, I don't care how you get me there, just get me there.

如果我输入URL,我不在乎您如何到达那里,只要让我到达那里即可。

UPDATE: It was asked in email "Whats a [good] way around postback URLs getting f'ed up when rewriting URLs." To answer that, I point you to an oldy, but a goody, a blog post with a clever title that no one really every appreciated, IMHO: "Postbacks for Algernon"

更新:在电子邮件中被问到“重写URL时回发URL烦恼的[好]方法是什么?” 为了回答这个问题,我将您引到一篇古老而又不错的博客文章,标题标题巧妙,没人真正欣赏,恕我直言:“ Algernon的回传

翻译自: https://www.hanselman.com/blog/permanent-redirects-with-http-301

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值