Skip Ribbon Commands
Skip to main content

Liam Cleary [SharePoint MVP]


Liam Cleary [SharePoint MVP] > Posts > SharePoint 2010 - Replace “HTTP” with “HTTPS” and shorten URL’s, based in internal and external
April 12
SharePoint 2010 - Replace “HTTP” with “HTTPS” and shorten URL’s, based in internal and external

Working with a client recently I had the old issue of them using "http://sharepoint" for internal users and then "" for external access. Of course as you would expect SharePoint takes care of most of the issues with ensuring the URL's for links are correct such as automatic navigation links, search results etc. However what it did not take care of as we all know is the hardcoded and manually added links to the pages and the ones that are were manually added to the master page so they were consistent across the board. This meant that when users came in from inside or outside it would either work or they would get redirected to the wrong URL for the zone they came in from. So how do we fix it? This time around I decided to use jQuery, to modify the links as then page was rendered. First I needed to ensure that the URL's were modified with either "HTTP" or "HTTPS" depending on which URL you came in from.

This code checks whether we are using "HTTP" or "HTTPS" then iterates through the "<a>" tag references and updates them accordingly. So this fixed half but I needed to make sure that if it was using "HTTP" then the URL's would change to the shortened "http://sharepoint". So I used the following code:

This code ran if the current protocol was "HTTP" then for any links that contain the FQDN it stripped them out to the shortened link, this was for the "" URL's . A similar approach was used for the URL's that contained just the "", also notice I added in the "HTTPS" link to "HTTP" change in the same line.

Of course these are all separate blocks of code but you can easily add them into one single loop that would check everything and modify accordingly. I found that due to me needing to check what the "HREF" contained and the order that I needed it I still needed to use one loop if running "HTTPS", as all the links that are hardcoded are using the FQDN, and for regular "HTTP" I needed two loops in this order to modify the main ones and then the second layer of links:

I am sure there are cleaner ways of doing this, could have written something in "C#" to modify the page etc. but had to use a "no-code" solution. So does that mean that jQuery is not code?? Just kidding J

comments powered by Disqus