Copied to clipboard

Flag this post as spam?

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


  • Josh Olson 79 posts 207 karma points
    Feb 20, 2013 @ 15:48
    Josh Olson
    0

    301 Redirect sub-domains to sub-folders (Umbraco vs. IIS)

    I am struggling with this issue and I have not been able to come up with a workable solution.  I spent two days now searching both Our and Stackoverflow to no avail.  Lots of similar problems but none of the solutions/suggestions seem to be working for me.

    I have this basic structure:

    |Home
    |PageA
    |PageB
    |PageFoo
    |PageBar
    |PageC

    with the URL: "site.domain.org" as the base of the site at the Home page.

    The DNS is configured to send *.site.domain.org to the IP address but what I need to have happen is if someone were to enter "foo.site.domain.org" into the browser window they get sent to "site.domain.org/foo" and similarly entering "bar.site.domain.org" will bring them to "site.domain.org/bar". There is a long, but finite list of these redirects I am trying to listen for, and all other traffic would simply end up at the main page.

    I have bungled around with the Manage Hostnames feature in Umbraco by setting a hostname on PageFoo for the address "foo.site.domain.org" and that works great for bringing up the page 'PageFoo', but the URL in the browser remains pointing to the non-existant "foo.site.domian.org" and I need that to change to "site.domain.org/foo". Oh yeah, and that all stops working once I start doing some standard SEO redirects in IIS (ie. enforcing the www, lowercase, trailing slash...). Perhaps another mistake in my configuration, but I would think that you should be able to do both?

    After failing at doing things within Umbraco, I turned my attention to IIS7.  Using the URL Rewrite from there (which adds the rules in web.config instead of the umbraco UrlRewriting.config) I have managed to make progress, but not yet reached a solution. I have gotten particularly stuck with the regex to parse out the subdomain while ignoring the presence, or lack thereof, of "http://" and/or "www."

    ^(http:\/\/)?(www\.)?(([^.]+)\.)?site\.domain\.org

    This expression works on everything I tested except breaks on "www.site.domain.org" as {R:4} in this case gives me "www".  If this is even an appropriate solution, someone with regex-foo might be able to suggest a fix?

    Finally, my two real questions: Is what I am trying to accomplish better to attack in Umbraco or in IIS (and I am curious to know why, not just get the concensus vote of the community), and how to progress with whichever is the best solution.

Please Sign in or register to post replies

Write your reply to:

Draft