复制代码 代码如下:
<system.webServer>
<rewrite>
<rules>
<rule stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^vevb.com$" />
</conditions>
<action type="Redirect" url="http://www.vevb.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Configuration;
namespace SiteSense.Domain
{
public class DomainLocation : IHttpModule
{
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.AuthorizeRequest += (new EventHandler(Process301));
}
public void Process301(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
HttpRequest request = app.Context.Request;
string lRequestedPath = request.Url.DnsSafeHost.ToString();
string strDomainURL = ConfigurationManager.AppSettings["WebDomain"].ToString();
string strWebURL = ConfigurationManager.AppSettings["URL301Location"].ToString();
//拦截到的Url不包含“”,而包含“vevb.com”
if (lRequestedPath.IndexOf(strWebURL) == -1 && lRequestedPath.IndexOf(strDomainURL) != -1)
{
app.Response.StatusCode = 301;
app.Response.AddHeader("Location", lRequestedPath.Replace(lRequestedPath, "http://" + strWebURL + request.RawUrl.ToString().Trim()));
app.Response.End();
}
}
}
}
复制代码 代码如下:
<appSettings>
<add key="WebDomain" value="vevb.com"/>
<add key="URL301Location" value="www.vevb.com"/>
</appSettings>
复制代码 代码如下:
<add type="SiteSense.Domain.DomainLocation, SiteSense.Domain"/>
上述两种实现301重定向的方法,只适合ASP.NET程序,不适用于ASP程序。
新闻热点
疑难解答
图片精选