6

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.)

3
  • Are you sure you've selected https binding in IIS for the site?
    – xoail
    Sep 14, 2015 at 14:49
  • Also consider looking into this SO question stackoverflow.com/questions/17273492/…
    – xoail
    Sep 14, 2015 at 14:51
  • 2
    Did you add port to the <site> definition in config? If so that'll be why, the link manager is not very clever!
    – jammykam
    Sep 14, 2015 at 17:13

5 Answers 5

7

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>
3

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>   
2

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

1

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/

3
  • I think this could have been an upvote and a comment on Jan's answer. Feb 21, 2018 at 13:55
  • This external link no longer works. Says the domain has expired. Please update your comment.
    – TxRegex
    Jun 18, 2018 at 18:27
  • What version is this for? It doesn't seem to work in 8.1 which only seems to understand the 'port' attribute.
    – Andy
    May 8, 2019 at 14:33
0

LinkManager: You can cheat the LinkManager by adding port="443" externalPort="80" to your site-definition in <sites>. Don't know if this will cause other issues though.

<configuration>
  <sitecore>
    <sites>
      <site name="website" port="443" externalPort="80" />
    </sites>
  </sitecore>
</configuration>

MediaManager: If you know the url, set the Media.MediaLinkServerUrl-setting, to prevent Sitecore from creating the wrong url. Otherwise...

class SslFriendlyMediaProvider : MediaProvider
{
    public override string GetMediaUrl(MediaItem item, MediaUrlOptions options)
    {
        var url = base.GetMediaUrl(item, options);

        if(options.AlwaysIncludeServerUrl)
            // https://example.com:443/a b?c=123 --> https://example.com/a%20b?c=123
            return new Uri(url).AbsoluteUri;

        return url;
    }
}

Config:

<configuration xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <mediaLibrary>
      <mediaProvider set:type="SslFriendlyMediaProvider, Assembly" />
    </mediaLibrary>
  </sitecore>
</configuration>

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.