Canonical Links

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 năm cách đây
Hi People

I have a quick question about Canonical links.

I am trying to further extend the ability to show the Canonical Tag on more pages then it's currently shown when having the "Enable canonical URLs" tick box on, e.g the home page.

Basically, if I try to add this code to a custom homepage view within my theme.

var canonicalUrlsEnabled = EngineContext.Current.Resolve<SeoSettings>().CanonicalUrlsEnabled;
    if (canonicalUrlsEnabled)
    {
        var HomePageUrl = Url.RouteUrl("HomePage", "", this.Request.Url.Scheme);
        Html.AddCanonicalUrlParts(HomePageUrl);
    }

When viewing the source I see the tag has a QueryString parameter of Length=0

<link rel="canonical" href="http://www.mysite.com/?Length=0" />

How could I remove the Length parameter?, Apologies if I am using the code incorrectly. I am still pretty new to NOPCommerce. Obviously I could use regex or a replace but I assume there must be something more graceful.

I would want to add this to most pages to prevent instances where a Google pay per Click Campaign (e.g appending ?gclid=32489234789349348) could result in generating additional URLs that could get indexed by accident.

Thanks!
12 năm cách đây
chease wrote:
var HomePageUrl = Url.RouteUrl("HomePage", "", this.Request.Url.Scheme);

Use
var HomePageUrl = Url.RouteUrl("HomePage", null, this.Request.Url.Scheme);
12 năm cách đây
Perfect Andrei - Thanks for this. I really should of tried that before posting - Cheers!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.