Redirect Sub-domain to Sub-directory (.Net Core)

Discussion in 'Site Programming, Development and Design' started by Graham Meehan, Jan 9, 2020.

  1. I've been trying to figure out for a while now if the following implementation is possible with WinHost and would be happy with any feedback.

    I have the following sub-domain:

    http://myapp.example.com

    I have an application startpoint for a .Net Core 3.0 app on a shared Windows server at the following path from the domain root:

    root/myapp

    I've modified the web.config in my domain's root directory as follows to be able to reach the application via the subdomain (myapp.example.com):

    <rule name="myapp.example.com" stopProcessing="true">
    <match url=".*" />
    <conditions>
    <add input="{HTTP_HOST}" pattern="^(www.)?myapp.example.com" />
    <add input="{PATH_INFO}" pattern="^/myapp/" negate="true" />​
    </conditions>
    <action type="Rewrite" url="\myapp\{R:0}" />
    </rule>

    While the application homepage loads fine initially with the proper url of myapp.example.com, when I make any requests in my application the URL displays as follows:

    http://myapp.example.com/myapp/{app routing}

    Problem: How would I remove the "myapp/" subdirectory path from the URL on all requests?

    I figure the required change should be made in one of the following locations:
    1. Domain root web.config
    2. Startup.cs in MyApp using URL Rewriting Middleware
    3. XML file imported with URL Rewriting Middleware in Startup.cs of MyApp.
    I am having a ton of issues understanding the .NET Core URL Rewrite Middleware if that is what needs to be used in this case.
     
  2. Elshadriel

    Elshadriel Winhost Staff

    Try getting your .NET Core application working from the root first (i.e. routing works without it appending /myapp), then move it to the /myapp sub-directory. Then apply the URL Rewrite rules you mentioned above.
     

Share This Page