关于asp.net的SEO优化问题(301重定向)
本人对优化就是菜鸟,求个问大哥指点下,看哪里出了问题?我的301重定向代码是: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不包含“www.jb51.net”,而包含“jb51.net”
if (lRequestedPath.IndexOf(strWebURL) == -1 && lRequestedPath.IndexOf(strDomainURL) != -1)
{
app.Response.Clear();
app.Response.StatusCode = 301;
app.Response.Status = "301 MovedPermanently";
//app.Response.AddHeader("Location", lRequestedPath.Replace(lRequestedPath, "http://" + strWebURL + request.RawUrl.ToString().Trim()));
app.Response.AddHeader("Location", lRequestedPath.Replace(strDomainURL, "http://" + strWebURL));
app.Response.End();
}
}
}
在web.config中加入:
<appSettings>
<add key="WebDomain" value="zhengchangfeedmill.com"></add>
<add key="URL301Location" value="www.zhengchangfeedmill.com"/>
</appSettings>然后重新生成后上传到服务器上,却只能实现首页重定向为带3W的网址www.zhengchangfeedmill.com,其他所有的子栏目页都不能重定向,求个问大哥指点下,是哪里出了问题? --------------------编程问答-------------------- 不用这样做吧 --------------------编程问答-------------------- 大哥 那要怎么样做的 在线等答案 实在是不懂,求指点 --------------------编程问答--------------------
public void Init(HttpApplication context)--------------------编程问答-------------------- 麻烦的域名解析跳转吧 --------------------编程问答-------------------- 3楼的兄弟 ,麻烦说清楚点,这段代码应该放在哪个位置? 菜鸟啊 --------------------编程问答--------------------
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e)
{
var app = sender as HttpApplication;
var context = app.Context;
string soureUrlStr = "baidu.com";
string targateUrl = "www.baidu.com";
if (context.Request.Path.IndexOf(soureUrlStr) > -1)
{
var path = context.Request.Path;
path = path.Replace(soureUrlStr, targateUrl);
context.RewritePath(path);
}
}
在方法public void Init(HttpApplication context)中
注释掉context.AuthorizeRequest += (new EventHandler(Process301));
加入context.BeginRequest += new EventHandler(context_BeginRequest);
--------------------编程问答-------------------- 楼上的大哥,按照你说的方法,连首页也不能重定向了,其他的页面也不能重定向啦,这是怎么会事啊,还有没有大侠来帮个忙? --------------------编程问答-------------------- 求路过此地的大侠,帮个忙啊
补充:.NET技术 , ASP.NET