IIS 6如何从http://example.com/*重定向到http://www.example.com/*

编程入门 行业动态 更新时间:2024-10-23 12:25:49
本文介绍了IIS 6如何从example/*重定向到www.example/*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用asp 3.5和IIS 6。

I am using asp 3.5 and IIS 6.

我们怎样才能自动重定向从 HTTP(S)网页://example/* 到 HTTP(S):// WWW .example的/ * ?

How can we automatically redirect pages from http(s)://example/* to http(s)://www.example/* ?

感谢。

推荐答案

我这样做是有一个HttpModule:

I did this with an HttpModule:

namespace MySite.Classes { public class SeoModule : IHttpModule { // As this is defined in DEV and Production, I store the host domain in // the web.config: <add key="HostDomain" value="www.example" /> private readonly string m_Domain = WebConfigurationManager.AppSettings["HostDomain"]; #region IHttpModule Members public void Dispose() { //clean-up code here. } public void Init(HttpApplication context) { // We want this fire as every request starts. context.BeginRequest += OnBeginRequest; } #endregion private void OnBeginRequest(object source, EventArgs e) { var application = (HttpApplication) source; HttpContext context = application.Context; string host = context.Request.Url.Host; if (!string.IsNullOrEmpty(m_Domain)) { if (host != m_Domain) { // This will honour ports, SSL, querystrings, etc string newUrl = context.Request.Url.AbsoluteUri.Replace(host, m_Domain); // We would prefer a permanent redirect, so need to generate // the headers ourselves. Note that ASP.NET 4.0 will introduce // Response.PermanentRedirect context.Response.StatusCode = 301; context.Response.StatusDescription = "Moved Permanently"; context.Response.RedirectLocation = newUrl; context.Response.End(); } } } } }

然后,我们需要的模块添加到我们的Web.Config:

Then we need to add the module to our Web.Config:

找到段&LT;的HttpModules&GT; 在&LT;的System.Web&GT; 部分,它很可能有一对夫妇在那里的其他条目已经,并加入类似:

Find the section <httpModules> in the <system.web> section, it may well have a couple of other entries in there already, and add something like:

<add name="SeoModule" type="MySite.Classes.SeoModule, MySite" />

您可以在这里的行动看到这一点:

You can see this in action here:

  • doodle.co.uk
  • doodlegraphics.co.uk
  • www.doodle-graphics.co.uk
  • doodle.co.uk
  • doodlegraphics.co.uk
  • www.doodle-graphics.co.uk

所有的 www.doodle.co.uk

更多推荐

IIS 6如何从http://example.com/*重定向到http://www.example.com/*

本文发布于:2023-11-01 11:40:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549247.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   IIS   http   www

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!