Page 1 of 1

Canonical URL Issue - Two Forward Slashes

Posted: Fri Jan 29, 2010 6:24 pm
by gardnerr
Hi,

The changes in 7.4 that add canonical urls to each page have caused an issue for me. I ran the IIS SEO tools and noticed that nearly every page was being crawled as http://localhost/category-c1.aspx and also http://localhost//category-c1.aspx - with two forward slashes. I have also noticed in the webmaster tools that Google is also seeing things that way.

I traced the issue to the fact that the canonical link has a %2F in it, instead of a forward slash, which comes from the HttpUtility.UrlEncode method. The only solution I can see is to replace each occurrence of %2F with a forward slash, which has solved the problem. This was done in the BindMetaTags function in PageHelper.cs.

Regards

Rob

Re: Canonical URL Issue - Two Forward Slashes

Posted: Wed Feb 17, 2010 12:40 pm
by meer2005
do you have an example of this?

Re: Canonical URL Issue - Two Forward Slashes

Posted: Thu Feb 18, 2010 2:32 pm
by Shopping Cart Admin
Hello Rob,

Thanks for the report, we'd identified this a few days ago while working on our new website. A hot patch will be available shortly. I am sorry this was overlooked in the forums and was missed in testing. Please report bugs to our ablecrm system.

Re: Canonical URL Issue - Two Forward Slashes

Posted: Thu Feb 18, 2010 4:34 pm
by Logan Rhodehamel
The file App_Code/PageHelper.cs has the broken code, around line 480 in the released version of the file. The broken method is BindMetaTags:

Code: Select all

    public static void BindMetaTags(Page page, ICatalogable catalogObject)
    {
        if (catalogObject != null)
        {
            StringBuilder htmlHead = new StringBuilder();
            htmlHead.Append(catalogObject.HtmlHead);
            if (!catalogObject.HtmlHead.Contains("<link rel=\"canonical\""))
            {
                string canonicalFormat = "<link rel=\"canonical\" href=\"{0}\" />";
                string objectUrl = page.ResolveUrl(catalogObject.NavigateUrl);
                htmlHead.Append(string.Format(canonicalFormat, HttpUtility.UrlEncode(objectUrl)));
            }
            page.Header.Controls.Add(new LiteralControl(htmlHead.ToString()));
        }
    }
To correct it, replace with this code:

Code: Select all

    public static void BindMetaTags(Page page, ICatalogable catalogObject)
    {
        if (catalogObject != null)
        {
            StringBuilder htmlHead = new StringBuilder();
            htmlHead.Append(catalogObject.HtmlHead);
            if (!catalogObject.HtmlHead.Contains("<link rel=\"canonical\""))
            {
                Uri storeUri = new Uri(Token.Instance.Store.StoreUrl);
                string canonicalFormat = "<link rel=\"canonical\" href=\"{0}\" />";
                string objectUrl = storeUri.Scheme + "://" + storeUri.Authority + page.ResolveUrl(catalogObject.NavigateUrl);
                htmlHead.Append(string.Format(canonicalFormat, objectUrl));
            }
            page.Header.Controls.Add(new LiteralControl(htmlHead.ToString()));
        }
    }

Re: Canonical URL Issue - Two Forward Slashes

Posted: Tue Jun 15, 2010 2:00 pm
by crazyjoe
This didn't fix my URL's. Google still is finding my URL's twice. One correctly and one with %2f added. Also, it created a log-in issue with my admin, and for those that were already in the admin, they couldn't save the changes they had made to products because the save button wouldn't show. Can you tell me what I may have done wrong. Has the coding above worked for anyone else? I would assume this must be a problem for everyone isn' t it? I am on Able 7.0.4