【问题标题】:How to redirect site to www if www is left off of request如果 www 没有请求,如何将站点重定向到 www
【发布时间】:2011-05-31 15:44:09
【问题描述】:

例如,我们有一个网站 www.domain.com。如果访问者忘记将 www 放在 url 请求中,如何将 URL 重写为 www.domain.com 的最佳方法?

我们正在使用 VS 2008 和 VB.Net 3.5

【问题讨论】:

  • 上下文是什么?您的意思是在 VS 中“如何进行字符串操作”?
  • 使用 301 重定向。 jesperastrom.com/seo/…
  • 这应该在 DNS 级别处理。确保 www.example.com 和 example.com 域设置指向相同的 IP 地址。

标签: vb.net visual-studio-2008 url url-rewriting


【解决方案1】:

您可以使用以下代码在 Global.asax 中的 Session_Start 事件中检测到它:

    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
    ' Fires when the session is started
    If Request.Url.Host.Contains("www.") = False Then
        Session.Abandon()
        Response.Redirect("http://www.domain.com")
    End If

End Sub

【讨论】:

    猜你喜欢
    • 2013-04-03
    • 2012-04-18
    • 2022-09-27
    • 2015-04-17
    • 2015-04-20
    • 1970-01-01
    • 1970-01-01
    • 2015-03-02
    • 2014-11-26
    相关资源
    最近更新 更多