Reputation: 593
I have hosted .net core web api as a website in iis, and added angular app as a application to the same website.
my application url is "http://example.com/angularapp" , now if users try using the url "http://example.com/" then I want them to get redirected to "http://example.com/angularapp".
Note: My api urls are like this - "http://example.com/api/xyz" and I dont want that to be impacted.
URL Rewrite rule that I tried in local environment
Upvotes: 0
Views: 3473
Reputation: 593
Regex $^ means "nothing", URL rewrite doesnt validate http and host names, but anything that is after the http and host names. So, In this case we expect only "Nothing". And for that case we are rewriting the app name to be appended to the URL.
Upvotes: 1
Reputation: 3042
Note: Pattern will not match http and host name. You'd better learn how to use url rewrite module first of all.
I'm not sure if you know how to edit web.config so I'll show the GUI of add the correct rule.
It will redirect http://example.com/
to http://example.com/angularapp
. BUT, if the url is http://example.com
, it won't redirect. I'm not sure if you want to redirect http://example.com
, so this just a remind.
Upvotes: 1
Reputation: 96
If not already installed, add the URL Rewrite module to IIS using the download here.
Once installed, select your site in IIS and you should see "URL Rewrite" as one of the options:
Open this and click "Add Rule(s)..." and add a blank Inbound rule. You can configure rewrite rules here to automatically route requests around your site. In your case, the regex pattern ^http://example.com/$
would work, however you'd probably want to look at refining/expanding your rewrite rules to account for things such as automatically redirecting to HTTPS, forcing a trailing slash etc.
Set the action to rewrite and define the Rewrite URL as the location you want matched requests to point to, in this case http://example.com/angularapp .
Note the above pattern would only match http://example.com/ and so your API requests would be unaffected.
Upvotes: 1