简体   繁体   English

指向第一个域的子文件夹的第二个域不会在IIS 8 URL重写中重写端口

[英]Second domain pointing to subfolder of first domain won't rewrite port in IIS 8 URL Rewrite

To try and make this as short as possible, I have two domains at work. 为了使它尽可能短,我有两个工作领域。

The first domain is our main domain at www.site1.com (port 80), pointing to a regular set up of a site in IIS 8, Server 2012. 第一个域是我们的主要域,位于www.site1.com(端口80),它指向IIS 8,Server 2012中的常规站点设置。

The second domain is at www.site2.com (port 8085), but using some clever URL rewrite wizardry that I found on SO, www.site2.com points to www.site1.com/site2/, but behaves as if it were it's own domain. 第二个域位于www.site2.com(端口8085),但是使用我在SO上找到的一些巧妙的URL重写向导,www.site2.com指向www.site1.com/site2/,但行为与它是自己的域名。 We did this in order to share assets between site1 and site2 in a .NET environment. 我们这样做是为了在.NET环境中在site1和site2之间共享资产。

I do not have DNS-level control, but have admin of the server and it's settings and have done all of the URL rewriting for both sites myself. 我没有DNS级别的控制权,但是拥有服务器及其设置的管理权限,并且自己完成了两个站点的所有URL重写。 We received a request to install an SSL cert on www.site2.com (port 444) so that we can set the site to HTTPS. 我们收到了在www.site2.com(端口444)上安装SSL证书的请求,因此我们可以将站点设置为HTTPS。 This is not relevant to the problem in itself because the problem exists in HTTP already. 这本身与问题无关,因为该问题已经存在于HTTP中。

The problem came about because another developer wants to be able to test the cert and the port configurations. 之所以出现此问题,是因为另一个开发人员希望能够测试证书和端口配置。 As of right now, this isn't possible even in HTTP. 截至目前,即使在HTTP中也无法实现。 Typing in www.site1.com:80 on the server works fine, but www.site2.com:8085 does not. 在服务器上输入www.site1.com:80可以正常工作,但www.site2.com:8085则不能。 site2 only connects properly when appended with www.site2.com:80 or just by typing in www.site2.com, I believe since it is rewritten as a subfolder off of site1. 仅当将site2附加到www.site2.com:80或仅键入www.site2.com时,site2才能正确连接,我相信,因为它被重写为site1的子文件夹。

I have tried everything I could think of in order to try and rewrite the ports in the URL so that the developer is able to test the port configuration by typing in www.site2.com:8085. 为了尝试重写URL中的端口,我已经尝试了所有可能的方法,以便开发人员能够通过输入www.site2.com:8085来测试端口配置。 The URL never resolves. 网址永远无法解析。

The bindings are set correctly as well because www.site2.com works fine in both test and production and has for years. 绑定设置也正确,因为www.site2.com在测试和生产中都可以正常工作,并且已经使用了很多年。 It only does not work when the correct port is added to the URL. 仅当将正确的端口添加到URL时,它才起作用。

This is the only code triggering the rewrite as it stands: 这是唯一触发重写的代码:

<rule name="www.site2 redirect" enabled="true">
    <match url=".*" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="^(www.)?site2.com$" />
    </conditions>
    <action type="Rewrite" url="/site2/{R:0}" />
</rule>

Any and all help would be appreciated. 任何和所有帮助将不胜感激。 Thanks. 谢谢。

You can do that in this way, just add one more condition into your rewrite rule: 您可以通过这种方式实现,只需在重写规则中再添加一个条件即可:

<rule name="www.site2 redirect" enabled="true">
    <match url=".*" />
    <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="^(www.)?site2.com$" />
        <add input="{HTTP_HOST}" pattern="^(www.)?site2.com:8085$" />
    </conditions>
    <action type="Rewrite" url="/site2/{R:0}" />
</rule>

Another way to to that with one condition is (remove $ from pattern in condiiton): 在一种情况下实现此目标的另一种方法是(从条件中的模式中删除$ ):

<rule name="www.site2 redirect" enabled="true">
    <match url=".*" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="^(www.)?site2.com" />
    </conditions>
    <action type="Rewrite" url="/site2/{R:0}" />
</rule>

But this rule will capture domains like that as well: site2.com.au, site2.com.fr, site2.com:{ANYPORT} etc. That's why i prefer first rule 但这条规则也将捕获这样的域: site2.com.au,site2.com.fr,site2.com{ANYPORT}等。这就是为什么我更喜欢第一条规则的原因

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM