本文介绍了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/*
发布评论