I have several applications installed on IIS:
/abc
/bcd
Now I want to redirect users coming to / to the /abc website. Since the root is not part of any application, I cannot use IIS Rewrite Module which uses redirects defined in web.config.
So I installed HTTP Redirection in IIS and enabled the following:

This works, if the user enters exactly http://example.com or http://example.com/, the server redirects to http://example.com/abc/.
However, if the user enters http://example.com/abc, the server treats the request as in the root directory, so it applies a redirection too, leading to http://example.com/abc/abc.
I also tried checking the first checkbox (Redirect all request to exact destination), but this leads to a redirection loop from http://example.com/abc to http://example.com/abc.
I want those users entering example.com/abc to stay there, and redirect users entering example.com to the /abc application. How can I do that?
To fix the redirect loop, you can add a trailing anchor link to the destination, for example: /abc/#. This prevents IIS from stripping the trailing slash and creating a redirect loop from http://example.com/abc to http://example.com/abc

Request URL:https://example.com/abc
Request Method:GET
Status Code:302 Redirect
Response Headers
Location:https://example.com/abc/#
Server:Microsoft-IIS/8.0
Request URL:https://example.com/abc/
Request Method:GET
Status Code:200 OK
Alternatively you can still use the URL rewrite module as discussed here even when it is for your root site and not an application. The web.config file should be present in your web root folder (typically %SystemDrive%\inetpub\wwwroot). You can also use the URL Rewrite UI in IIS Manager to add an inbound rule:

This will redirect http://example.com/ to http://example.com/abc/.
If the user enters http://example.com/xyz (and that file does not exist) they will not be redirected to /abc and will receive a 404, unlike the HTTP redirect module above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With