1

We have a server that hosts two applications on the same default site.

Default Web Site

 Inventory

 Expenses

We also have two DNS names pointing to the same ip address:

 myinventory.mycompany.com

 myexpenses.mycompany.com

We would like to have a redirect rule to point to:

myinventory.mycompany.com  -->  myinventory.mycompany.com/Inventory

and

myexpenses.mycompany.com  --> myexpenses.mycompany.com/Expenses

We have tried a ton of redirect/rewrite rules, but have not been successful in getting this to work. Wea re able to to a full redirect but we have to pick a single site. Any ideas on how to accomplish this?
Thanks, Mike

1
  • What are you using to do redirects?
    – Richard Seal
    Jun 23, 2023 at 14:14

2 Answers 2

0

You could just add a field to your base template Redirect To Url. Then check for it in the main layout. If found, do a manual redirect.

That should get past the issue with different sites, as this is per item not site.

var redirectUrl = Model.Item["Redirect To Url"];
if (!string.IsNullOrWhiteSpace(redirectUrl))
{
    Response.RedirectPermanent(redirectUrl, true);
    return;
}
0

As mentioned you tried different redirect rules could you please share one of them to understand what's wrong with them?

Having said that could you please also try the below rule for one of your requirements?

<rule name="Redirect to Inventory" stopProcessing="true">
  <match url="^$" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^myinventory\.mycompany\.com$" />
  </conditions>
  <action type="Redirect" url="http://{HTTP_HOST}/Inventory" />
</rule>

Here's a breakdown of the rule:

name: Specifies a name for the rule (you can change it if desired).

stopProcessing: Indicates that no further rules should be processed if this rule matches.

match url: Matches the URL path. In this case, ^$ matches the root URL (/).

conditions: Contains the conditions for the rule to be applied. In this case, it checks if the HTTP host is myinventory.mycompany.com.

action: Specifies the action to take if the rule matches. In this case, it performs a redirect to http://{HTTP_HOST}/Inventory.

Remember to apply the rule to your IIS configuration, either by adding it to your web.config file or using the IIS management interface.

Note: Make sure to replace http with https if your website uses HTTPS. This rule assumes you're using IIS's URL Rewrite Module.

Hope this might help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.