Have you every written a blog post, and got some helpful comments from folks who have a better way to do something? Well that’s exactly what this is!

My last blog post http://www.techrevmarrell.com/create-a-sharepoint-vanity-ish-shortened-url-and-redirect-to-a-site-collection/ Was about a requirement I had to create a shortened URL that they could provide to users and this shortend url would automatically redirect a user to another site collection.

Well the method I ended up using was to create an explicit Managed Path to create the shortened url. Some asked why I just didn’t use a DNS entry, and for my particular requirement, it wasn’t available to me, nor was a redirect at the load balancer level. So for the URL shortner explicity Managed Path. Again to see how I did it, you can check out the link above.

Now the second thing I did was create a webpart page, and add a JavaScript redirect (really just meta tag redirect) to the homepage of the site collection that I wanted to redirect.
I mentioned this wasn’t the cleanest option and I’d already tried to utilize IIS URL Rewrite to solve my issue, and I had, (will come back to this shortly) but when my users did some testing on my solution, everything was great on the Desktop side, but on the mobile device side the solution failed. And this was because I used a web part page to put my Content Editor Web part that contained my redirect script. And unless you disable the mobile browser feature, the default mobile view of a SharePoint page will not display webparts.  And with no webparts loaded, no redirect code loaded, so users were not redirected. #YeahUATWIN!

So anyways I decided I really needed to give the IIS URL Rewrite another look. The biggest issue I ran into IIS URL Rewrite was I was trying to accomplish 2 different tasks at once with it. I wanted to utilize it to create a quasi URL Shortner using some Rewrite function, and also redirect. I ended up creating an odd loop and figured it was just not to be. But coming back to it, I realized that the URL shorten piece was something my managed path solution could handle just fine. All I need from IIS URL Rewrite was for it to redirect the shortened URL to the correct site collection.

This was actually very easy to implement.
I’d already installed IIS URL Rewrite on my server. If you don’t already have it, you’ll need to install it on each of the web front end servers where traffic will be coming in from.
https://www.iis.net/downloads/microsoft/url-rewrite  (note: it will restart w3wp) services on your server.

Once it was installed,  I selected the site in IIS that I wanted to run it against, then clicked the URL Rewrite icon.

After that I click Add Rule(s)…, selected a blank rule.
Then I added a Rule Name and set it up per the screenshot below. The resulting redirect worked flawlessly. And UAT testing was much better.
So at the end of the day, there was a better way! Thanks to those who replied and let me know. Now if someone does have a way to do URL Shortening with IIS URL Rewrite (NOT DNS), please let me know. 🙂 I’m all ears!


Happy SharePointing!