How to redirect a subdomain to a subdirectory?

Discussion in 'Getting started' started by robertt, Jul 27, 2010.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Can someone show me step by step how to redirect a subdomain to a subdirectory, please?

    I want blog.mydomain.com subdomain to point to /blog subdirectory which contains MVC ASP.NET application.
    I need exact steps to setup blog.mydomain.com subdomain, exact content of "default document", what is its file name etc.
     
  2. OK I figured out most of the problems. But still I have one problem,
    when I redirect from blog.mydomain.com to mydomain.com/blog the url
    is blog.mydomain.com/blog, but I want it to be blog.mydomain.com. Because of this my MVC app can't find the views.
     
  3. Hi roberrt,

    How did you solve your problem? I am interested on what you did.
     
  4. Having the exact same issue.
    Do I need to create a virtual directory? If so, how do I do this without having admin rights on the box?
     
  5. If your account is hosted under our IIS7 server then you can use URL Rewrite. For more information please view this blog post.
     
  6. leonardyuri

    leonardyuri Guest

    As far as I know you need to create a new redirect for that then create a path I think. I've tried it once but I don't remember the procedure but when your there in your hosting you'll know for sure.
     
  7. I am having a problem getting http://subdomain1.domain.com/ to work. I have created the ASPX page to redirect to http://domain.com/subdomain1/. I would like my users to see http://subdomain1.domain.com/, so I wrote a URL Rewrite to rewrite subdomain1/ to / but I get the following error when I do:

    This webpage has a redirect loop

    The webpage at http://domain.com/subdomain1/ has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.

    This makes sense, as I am causing an infinite loop. But I am not sure I know how to fix it. Any suggestions?
     
  8. Figured it out thanks to a nice write up by owscott over at http://weblogs.asp.net/

    The solution was to ditch the redirector in code, and use the condition tags to parse

    <rewrite>
    <rules>
    <rule name="subdomain1.domain.com" stopProcessing="true">
    <match url=".*" />
    <conditions>
    <add input="{HTTP_HOST}" pattern="^subdomain1.domain.com$" />
    <add input="{PATH_INFO}" pattern="^/subdomain1/" negate="true" />
    </conditions>
    <action type="Rewrite" url="\subdomain1\{R:0}" />
    </rule>
    </rules>
    </rewrite>
     
  9. Good job. Absolutely agree this method is better and Scott's blog is very helpful.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page