简体   繁体   English

301重定向为seo

[英]301 redirect for seo

I have a site on which I ran a woorank report. 我有一个网站,我在其上运行了一个woorank报告。 One of the items it's reporting is: 其报告的一个项目是:

www resolve Be careful! Your website without www doesn't redirect to www (or the opposite). It's duplicate content! Hide advice
High impactEasy to solve
Be sure that http://mysite.com and http://www.mysite.com are not running in parallel.

Redirecting requests from a non-preferred hostname is important because search engines consider URLs with and without "www" as two different websites.

Once your preferred domain is set, use a 301 redirect for all traffic to your non-preferred domain.

I read a few posts online and was wondering what QUICK AND EASY solution there is to fixing this in asp.net 4. 我在线阅读了一些帖子,并想知道在asp.net 4中有什么快速和简便的解决方案。

Thanks. 谢谢。

had exact same problem, fixed it with this in my global asax basically i redirect you with 301 if you ask for my site without the www. 有完全相同的问题,修复它在我的全球asax基本上我重定向你301如果你要求我的网站没有www。 by the way you most likely wont need the if( url rewriting) stuff. 顺便说一句,你很可能不需要if(url重写)的东西。 just the line in the else with do the job. 只需要在其他地方完成工作。

void Application_BeginRequest(object sender, EventArgs e)
        {
            try
            {
                if (HttpContext.Current.Request.Url.AbsoluteUri.ToLower().StartsWith("http://mysite"))
                {
                    string newUrl = string.Empty;
                    if (HttpContext.Current.Items["UrlRewritingNet.UrlRewriter.VirtualUrl"] != null)
                        newUrl = "http://www.mysite.com" + HttpContext.Current.Items["UrlRewritingNet.UrlRewriter.VirtualUrl"].ToString();
                    else
                        newUrl = HttpContext.Current.Request.Url.AbsoluteUri.ToLower().Replace("http://mysite", "http://www.mysite");



                    Response.Status = "301 Moved Permanently";
                    Response.StatusCode = 301;
                    Response.StatusDescription = "Moved Permanently";
                    Response.AddHeader("Location", newUrl);
                    Response.End();
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM