Canonical URL Issue - Two Forward Slashes

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
gardnerr
Ensign (ENS)
Ensign (ENS)
Posts: 20
Joined: Sun Oct 04, 2009 3:57 pm

Canonical URL Issue - Two Forward Slashes

Post by gardnerr » Fri Jan 29, 2010 6:24 pm

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

meer2005
Captain (CAPT)
Captain (CAPT)
Posts: 245
Joined: Wed Feb 09, 2005 2:00 pm

Re: Canonical URL Issue - Two Forward Slashes

Post by meer2005 » Wed Feb 17, 2010 12:40 pm

do you have an example of this?

User avatar
Shopping Cart Admin
AbleCommerce Admin
AbleCommerce Admin
Posts: 3055
Joined: Mon Dec 01, 2003 8:41 pm
Location: Vancouver, WA
Contact:

Re: Canonical URL Issue - Two Forward Slashes

Post by Shopping Cart Admin » Thu Feb 18, 2010 2:32 pm

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.
Thanks for your support

Shopping Cart Guru
AbleCommerce.com
Follow us on Facebook

User avatar
Logan Rhodehamel
Developer
Developer
Posts: 4116
Joined: Wed Dec 10, 2003 5:26 pm

Re: Canonical URL Issue - Two Forward Slashes

Post by Logan Rhodehamel » Thu Feb 18, 2010 4:34 pm

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()));
        }
    }
Cheers,
Logan
Image.com

If I do not respond to an unsolicited private message, it's not because I'm ignoring you. It's because the answer to your question is valuable to others. Try the new topic button.

crazyjoe
Commander (CMDR)
Commander (CMDR)
Posts: 172
Joined: Mon Apr 26, 2010 2:20 pm

Re: Canonical URL Issue - Two Forward Slashes

Post by crazyjoe » Tue Jun 15, 2010 2:00 pm

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
Crazy Joe Sadloski
Webmaster
Hot Leathers Inc.
http://www.hotleathers.com

Post Reply