skip to Main Content

Having a sitecore website. Situation is for every country, there are two URLs that you can use to hit the homepage.

www.abc.com/en/home

and

www.abc.com/en

We only want one – this is bad for both SEO and analytics.
I want to retire www.abc.com/en/home and want www.abc.com/en to only work.

I already worked with embedded URL = always in web.config but didn’t worked for me.

3

Answers


  1. Chosen as BEST ANSWER

    With the help of you guys all finally my bug is resolved and I came up with code which works in every situation like appended query string or without it.

    string baseUrl = Sitecore.Links.LinkManager.GetItemUrl(Sitecore.Context.Item);
                    if (baseUrl.ToLower().Contains("?"))
                    {
                        baseUrl = Request.RawUrl.Substring(0, Request.RawUrl.IndexOf("?"));
                    }
                    string Qurl = Request.RawUrl;
                    string AppendedUrl = string.Empty;
    
                    if (Qurl.ToLower().Contains("?"))
                    { 
                        Qurl = Request.RawUrl.Substring(0, Request.RawUrl.IndexOf("?")); 
                        AppendedUrl = Request.RawUrl.Substring(Qurl.Length);
                    }
                    string fullPath = baseUrl + AppendedUrl;
                    if (baseUrl != Qurl)
                    {
                        Response.RedirectPermanent(fullPath);
                    }
                }
            }
    

    Try this :)


  2. If you use LanguageEmbedding.Always in the LinkManager.
    Links generated with the Sitecore LinkManager have always a language code.
    But the other urls will also work.

    You can use a Canonical see Tip 17 for search engines.

    Or you can do a redirect if the url not match with the url you want.

    Or block/redirect the url’s in you netwerk/loadbalancer/webserver or redirect module or Sitecore <httpRequestBegin>pipeline. (just what you find convenient)

    A simple solution is place a peace of code in your master page something like this:

    string baseUrl = LinkManager.GetItemUrl(Sitecore.Context.Item);
    if (baseUrl != Request.Path)
    {
        Response.RedirectPermanent(baseUrl);
    }
    

    Also works for url aliases.

    Login or Signup to reply.
  3. Use the IIS URL Rewrite module with the following rule:

    <rule name="Redirect home" stopProcessing="true">
        <match url="^/en/home/?$" />
        <action type="Redirect" url="/en/" />
    </rule>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search