【发布时间】:2014-03-19 17:33:54
【问题描述】:
Google 已将我们的一些页面同时使用 HTTPS 和 HTTP 编入索引。我想将不应该是 HTTPS 的页面重定向回 HTTP (301)。
这是一个 EPiServer 7 站点,但本质上是 MVC。
我的控制器中有以下内容..
if (currentPage.RequireSsl != null && currentPage.RequireSsl.Value && !HttpContext.Request.IsSecureConnection)
{
if (HttpContext.Request.Url != null)
{
return this.RedirectPermanent(HttpContext.Request.Url.ToString().Replace("http:", "https:"));
}
}
else if (HttpContext.Request.IsSecureConnection && (currentPage.RequireSsl == null || currentPage.RequireSsl.Value == false))
{
if (HttpContext.Request.Url != null)
{
return this.RedirectPermanent(HttpContext.Request.Url.ToString().Replace("https:", "http:"));
}
}
现在,如果请求非 https 的“安全”页面,它会执行我想要的操作,它会 301 到 https(在 fiddler 中查看时)。
**GET http://domainxx.com/section/securepage/
301 Moved Permanently to https://domainxx.com/section/securepage/**
但是,如果我在 HTTPS 上请求非安全页面,它会重定向,但我会得到 200 状态码,而不是 301。Fiddler 甚至没有列出直接:
**GET http://domainxx/section/notsecurepage/
200 OK (text/html)**
【问题讨论】:
-
好的,这实际上没问题.. Fiddler 没有接收 HTTPS 请求,但 howto301redirect.com/301-redirect-checker 是,并且工作正常。
标签: asp.net-mvc-4 redirect iis-7 http-status-code-301 episerver