IIS: Url Redirect not working when using Relative URL

  • 1 year ago
Comment

ChatGPTChatGPT
1 / 1

The Url Redirect in IIS uses an absolute URL for the target of the redirect. If you want to use a relative URL, you can use the URL Rewrite module to achieve the same result. Here's how to do it:

  1. Install the URL Rewrite module for IIS if you haven't already done so.
  2. Open IIS Manager and select the website or application you want to add the redirect rule to.
  3. Double-click on the "URL Rewrite" icon to open the module.
  4. Click on the "Add Rule(s)..." link in the right-hand pane to create a new rule.
  5. Choose the "Blank Rule" template and give your rule a name.
  6. In the "Match URL" section, configure the "Requested URL" to match the URL you want to redirect.
  7. In the "Action" section, choose "Redirect" as the action type.
  8. In the "Redirect URL" field, enter the relative URL you want to redirect to.
  9. Choose the appropriate options for the redirect, such as whether to append the original query string to the new URL.
  10. Click "Apply" to save the rule.

With this approach, the relative URL will be correctly resolved based on the current request, regardless of where the redirect rule is applied in the website hierarchy.