Redirect subdomain URL to another subdomain in IIS

I need to redirect a "fake" subdomain to a real subdomain in IIS 7.5. The reason is that the marketing department does not want to use the actual website address in the printed materials.

Actual site URL:

reporting.usapartners.com

The marketing department wants report.usapartners.com (fake) to redirect to report.usapartners.com (real)

Again, report.usapartners.com does not exist, only report.usapartners.com exists

Here is what I tried

I added a binding in IIS for report.usapartners.com. I added report.usapartners.com as the host name and used the IP address of report.usapartners.com

Then I went to report.usapartners.com web.config and added:

<rewrite> <rules> <rule name="report" stopProcessing="true"> <conditions logicalGrouping="MatchAll"> <add input="{HTTP_HOST}" pattern="report.usapartners.com" negate="false" /> </conditions> <action type="Redirect" url="http://reporting.usapartners.com" appendQueryString="false" redirectType="Permanent" /> </rule> </rules> </rewrite> 

It looks like my solution creates an alias that cannot be redirected to.

Am I even right about this problem? It seems like this should be a simple problem to solve, but maybe not? Any ideas are welcome and appreciated.

thanks

+6
source share
2 answers

I think you need to create a separate site with host bindings for report.usapartners.com (fake site) in IIS. This will be a stub site (it will still need a disk path, but it will have web.config there), in which there will be only a redirection rule.

Now click HTTP Redirect for this site in IIS and check Redirect requests to this destination and put http://reporting.usapartners.com in the text box. Then check the box Redirect all requests to exact destination (instead of relative to destination) , do not go out the next one, and then select the Permanent (301) status code Permanent (301) .

If you want to redirect and save subdirectories and / or the query string, you can change the contents of the text field as http://reporting.usapartners.com$S$Q . Please note that in this case there is no slash. $S saves subdirectories, and $Q saves the query string.

+7
source

Your rule triggers a redirect loop.

Observe what your rule does:

  • Matches any given URL (this includes "/", "/ something", "/something/another.html", etc.).
  • If the host name is NOT "report.usapartners.com"
  • Forever redirect the request to " http://reporting.usapartners.com "

So, as you can see, as soon as the user is redirected to the reporting subdomain, he is again redirected to the reporting, because the host name is not "report.usapartners.com".

The key here is the negate="true" attribute in the rule condition. Delete it or set it to false and you're good to go. Strike>

Edit:

You are almost there.

The real solution would be to change the host name in the rule to the desired host, while maintaining the negation true, so your rule would do:

  • Matches any given URL (this includes "/", "/ something", "/something/another.html", etc.).
  • If the host name is NOT "report.usapartners.com"
  • Forever redirect the request to " http://reporting.usapartners.com "

code:

 ... <add input="{HTTP_HOST}" pattern="reporting.usapartners.com" negate="true" /> ... 
+3
source

Source: https://habr.com/ru/post/973232/


All Articles