SOLUTION: I couldn't see a way to put multiple HTTP Redirect rules in place easily via IIS 7 for a single site so I decided to use "URL Rewrite 2.0" for IIS 7, a module/extension for IIS provided by Microsoft that has to be downloaded and installed separately (watch out for the first gotcha!)
- To install download it from http://www.iis.net/downloads/microsoft/url-rewrite which will install it via the Web Platform Installer... BUT... be aware, that despite a lack of warning it will:
- Stop all the websites on your server.
- Require a server reboot before you can use it
- After you've scrambled to reboot your server after seeing all your sites down then it's simply a matter of opening the "URL Rewrite" module you'll now see in IIS for your site and creating a number of redirect rules - here is some info: http://www.iis.net/learn/extensions/url-rewrite-module/using-the-url-rewrite-module but this is what I did
- Requested URL = Matches Pattern
- Using = Regular Expressions (man, these always suck if you haven't learnt them! A cheat sheet might help you: http://regexlib.com/CheatSheet.aspx ... I find trying to search for regular expressions in regexlib is pointless if it's a general concept you're looking for e.g. "find me all matches with a word but not having this word" vs "email validator")
- Pattern: e.g. (?!.*timetable.*)^clubs/(.*)/(.*)$
- Matches any URL that starts with clubs/ and doesn't contain the word timetable
- Another example: ^clubs/(.*)/(.*)/timetable.*$
- Matches any URL that starts with clubs/ and then has timetable at the end
- Ignore case = ticked
- Action Type: Redirect
- Redirect URL: e.g. http://yoursite.com/clubs/{R:1}/{R:2}/ (see how you can grab anything from the regular expression that was in brackets (known as a back reference apparently) and use it in the redirect URL.
- Another example: http://yoursite.com/clubs/{R:1}/{R:2}/timetable/
- Append Query String = false (not required since we were using friendly urls without query strings anyway).
- Redirect Type: Permanent (301).
- To ensure all other pages are redirected to the root of your homepage simply update your HTTP Redirect settings in IIS
- Redirect requests to this destination: Ticked
- http://yoursite.com/
- Redirect all requests to exact destination (instead of relative to destination).
- Status code: Permanent (301).
No comments:
Post a Comment