Redirect IIS's root to application root
Asked Answered
L

1

6

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:

enter image description here

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?

Lakin answered 26/3, 2015 at 14:21 Comment(0)
I
7

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

IIS HTTP Redirect Configuration

Example redirect

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

URL rewrite module

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: IIS URL Rewrite Edit 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.

Infant answered 2/3, 2016 at 22:9 Comment(1)
Why the pattern ^$, could you please explain?Rosin

© 2022 - 2024 — McMap. All rights reserved.