switching between www and non-www

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 anni tempo fa
hey guys

in 1.9 and in 2.0
by default, mydomain.com and www.mydomain.com are 2 different websites and this is bad for search engines

in 1.9 i added in global.asax the following code and this solved it
when someone puts mydomain.com in the browser it gets moved directly to www.mydomain.com
is there anywhere we can insert it in 2.0 ????
thank you

    void Application_BeginRequest(object sender, EventArgs e)
    {
    if (Request.Url.Authority.StartsWith("www"))
        return;

    var url = string.Format("{0}://www.{1}{2}",
                     Request.Url.Scheme,
                     Request.Url.Authority,
                     Request.Url.PathAndQuery);

    Response.RedirectPermanent(url,true);
    }
12 anni tempo fa
anything about this guys ?????
12 anni tempo fa
I guess best way to solve this is to open up the source and paste your code into the global.asax, build, compile using the .bat files that are provided and copy the Nop.Web.dll to your project bin folder.
12 anni tempo fa
solved
odd that also in 2.0 the same script worked
havent tried it before posting

this is what global.asax contains now

<%@ Application Codebehind="Global.asax.cs" Inherits="Nop.Web.MvcApplication" Language="C#" %>

<script runat="server">

    void Application_BeginRequest(object sender, EventArgs e)
    {
    if (Request.Url.Authority.StartsWith("www"))
        return;

    var url = string.Format("{0}://www.{1}{2}",
                     Request.Url.Scheme,
                     Request.Url.Authority,
                     Request.Url.PathAndQuery);

    Response.RedirectPermanent(url,true);
    }

</script>
12 anni tempo fa
I noticed my website is showing up in Google with and without the "www".
Even when the website shows up 2 times on the same results page, it is listed as :

MyWebSite  and
www.MyWebSite

In IIS, I have the website listed under "Default Web Site"
as
MyWebSite and not www.MyWebSite

Should I change it to www.MyWebSite ?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.