Ayman Barhoum
Ayman Barhoum

Reputation: 1255

Sitecore Redirect urls

I am working on 301 url redirects, i tried some Sitecore redirect modules before, but i am looking for recommended approach, actually i have requirements to remove language code "en" from the URL if the language is English and keep it for other languages, i did that in link manager and for example when the user click on about us link, it will take him to the page without language code like this:

www.mywebsite.com/about-us

but still i can access the url with language code manually like this :

www.mywebstie.com/en/about-us

so now i have two urls to the same page. and this is not recommended for the SEO. and in the end i want only one url for each page.

another example also, about us can be access with hyphen

www.mywebstie.com/about-us

and with space

www.mywebstie.com/about us

what is the best approach to solve this issue ?

Upvotes: 1

Views: 1367

Answers (2)

Anton
Anton

Reputation: 9961

There is wide range of options how you can achieve required behavior:

  1. You could configure your Sitecore website

    Configure LinkManager (Sitecore.config): Change settings in default LinkProvider. For excluding language from URLs set languageEmbedding="never" languageLocation="queryString".

    Configure encodeNameReplacements (Sitecore.config): add this rule

    <replace mode="on" find=" " replaceWith="-">

    to replace spaces with dashes.

  2. Use canonical links

  3. Write your own LinkProvider for your purpose

  4. Install and configure IIS extensions that could redirect your requests.

    e.g.: URL Rewrite, Ionic's Isapi Rewrite Filter or ISAPI_Rewrite But be careful if you plan to use this modules on CM instance.

I would recommend you try to configure your Sitecore LinkManager provider, encodeNameReplacement rules (item 1 in list) and add canonical links (item 2 in list). It seems that it will be enough for your task.

If configuration and canonical links will not be enough, you could extend default Sitecore behavior(item 3 in list) or install and configure IIS modules(item 4 in list).

Upvotes: 1

Jan Bluemink
Jan Bluemink

Reputation: 3487

Use a Canonical is an option, <link id="Canonical" rel="canonical" href="/about-us/" /> then you SEO problem is gone.

Or just creat the redirect in your MasterPage somethings like this:

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

Beside the variant you already mentioned, this will also work /about-us.aspx and /about-us.ashx. Other option is, You can certainly also solve this in the httpRequestBegin pipeline, ItemResolver.

Upvotes: 2

Related Questions