Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sitecore adding port numbers to all URLs

Wondering if anyone has seen this behavior before. My instance of Sitecore 6.6 appends the port number to all the URLs it generates for my site. So for example, a link to the home page should be "https://example.org", but instead it's generated as "https://example.org:443". Everything functions fine with the port numbers, but it's muddling some stuff we're trying to do with SEO and canonicalization. Does anyone know if there's a setting or setup to not produce the port numbers? (I'm sure I could rewrite the URLs by catching them at the appropriate point in the pipeline, but I'm hoping for a simpler way before I jump to that.)

like image 399
gfrizzle Avatar asked Sep 14 '15 14:09

gfrizzle


4 Answers

This is caused by having the 'scheme' property in the configuration/sitecore/sites/site element of the web.config (or patched config) being set to 'http' explicitly, but making requests over SSL. Removing this, or setting it to 'https' resolves the issue.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <sites>
      <site patch:before="*[@name='website']"
                name="my_website"
                hostName="my_website.com"
                scheme="http" 
                ...
    </sites>
  </sitecore>
</configuration>   
like image 43
medkg15 Avatar answered Oct 19 '22 17:10

medkg15


The Sitecore LinkManager is indeed not so clever. We also experienced this issue with a mix of proxy servers and load balancers. To remove the ports, we have created a custom LinkProvider which removes the port if needed (untested code sample):

public class LinkProvider : Sitecore.Links.LinkProvider
{
   public override string GetItemUrl(Item item, UrlOptions options)
   {
      var url = base.GetItemUrl(item, options);
      if (url.StartsWith("https://"))
      {
         url = url.Replace(":443", string.Empty);
      }

      return url;
   }
}

And configure the new LinkProvider:

<configuration xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <linkManager defaultProvider="sitecore">
      <providers>
        <add name="sitecore" set:type="Website.LinkProvider, Website" />
      </providers>
    </linkManager>
  </sitecore>
</configuration>
like image 101
Kevin Brechbühl Avatar answered Oct 19 '22 17:10

Kevin Brechbühl


It's a known bug: https://kb.sitecore.net/articles/913585

There is a patch for releases below 9.1 available here: https://github.com/SitecoreSupport/Sitecore.Support.93141/releases

like image 2
sitecorepm Avatar answered Oct 19 '22 18:10

sitecorepm


I agree with Jan's findings: setting externalPort on the site node in the configuration convinces Sitecore to exclude the port in a generated URL. I did a full write-up on my blog, including using the result for canonical URL tags.

http://findgnosis.com/2017/06/26/hiding-port-urls-produced-sitecores-linkmanager/

like image 1
Chris Elston Avatar answered Oct 19 '22 18:10

Chris Elston