Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Niels Jorck Ellegaard 39 posts 245 karma points
    Oct 11, 2013 @ 16:19
    Niels Jorck Ellegaard
    1

    Common Redirect rules for Umbraco

    You know how we stumple upon something tedious at times and the nerd in us want to make code to fix it?

    I had a project with a lot of domains and got annoyed at hardcoded redirect rules, so I made some rules to match all of it.

    That was when I realized our redirect rules were terrible!
    And so began my nerdy quest for creating the "perfect" redirect rules.

    During my research I found that A LOT of people are having trouble getting even simple redirect rules to work properly. And I noticed that a lot of the project I saw elsewhere had the exact same issue.

    Because I found so many people having issues with redirect rules, I have decided to make a nuget package with the redirect rules I use.

    I hope this can help other Umbracos getting a nice and steamlined url structure.

    And atleast, the link for the nuget package! (My very first package aswell)
    https://www.nuget.org/packages/RedirectRules/

    What does it do?

    The "basic rules"

    • Remove trailing slash. (Pages are still accessable with trailing slash if the url generation is set without in Umbraco)
    • Lowecase urls. (Urls can be mixed of upper and lowercase. Now it is only lowercase. Images and so on, are excluded.)
    • Remove default.aspx. (This is a bit situational, because the page can be called a lot of things)
    • Trim .aspx. (Same as with trailing slash. And I dislike the .aspx as it is unnessesary and in my opinion ugly.)
    • Subdomains without www. (For subdomains I remove any www. prefix. This is just a personal preference, and therefore how the rules are set up. No hardcoded deomains!)
    • Topdomains WITH www. (Again, personal preference. No hardcoded deomains!)
    Now that is the basics in my opinion. But I have spent quite some time making them even better, so these are the features that makes them great!
    • No 301 chaining! (The url is fixed completely before redirecting. Normally you will redirect once for every rule.)
    • Keep https (I test if you come from http or https and make sure you stay on that. Most rules are hardcoded)
    • Whitelists. (To avoid problems with upgrading umbraco, umbraco backend, Ajax calls, Api calls or whatnot. I also included localhost here to easy development)
    • No redirect caching. (301: Permanent redirect, is a bit more permanent than I think most concider the web. A 301 redirect is cached in the browser of every client. It will not be cleared with a Ctrl+F5, you have to clear it manually. Meaning, if you make a redirect and at some point in the future you want to use that page again, you cant. Well... Now you can! )
    Are there any issues?
    Yes... It isn't perfect. The way I test if it is a subdomain is with the amount of punctuation marks. So mysite.co.uk would be counted as a subdomain even though it is a topdomain. I haven't had the need for a co. domain yet so I havent gone into that, but at some point I will.

    If you have any comment/feedback on the rules, the package or anything else for that matter, feel free to leave a comment here, on nuget or wherever you might find me.

    I hope you can use them! :)

Please Sign in or register to post replies

Write your reply to:

Draft