IIS重写总是触发相同的规则
我在配置IIS进行URL重写时遇到问题 我有一个应用程序在tomcat上运行,使用端口1512,IIS在端口80上运行,我想捕获两种不同的情况: 1) 在端口80上传入的调用没有任何附加组件myserver:80/,应该路由到myserver:1512/pim/webaccess 2) url myserver:80/pim/scripts/script.js中包含pim的调用应路由到myserver:1512/pim/scripts/script.js 我设置了两条规则,如下所示,但在运行此规则时,它总是触发上面示例1中的规则,从而返回登录页面,而不是js文件。不知道我做错了什么 指向脚本文件等的链接位于登录页面中的/pim/scripts/script.js格式,是否与此有关 现在真的很沮丧:pIIS重写总是触发相同的规则,iis,url-rewriting,url-routing,Iis,Url Rewriting,Url Routing,我在配置IIS进行URL重写时遇到问题 我有一个应用程序在tomcat上运行,使用端口1512,IIS在端口80上运行,我想捕获两种不同的情况: 1) 在端口80上传入的调用没有任何附加组件myserver:80/,应该路由到myserver:1512/pim/webaccess 2) url myserver:80/pim/scripts/script.js中包含pim的调用应路由到myserver:1512/pim/scripts/script.js 我设置了两条规则,如下所示,但在运行此规
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpRedirect enabled="false" destination="http://myserver123:1512/pim/webaccess" exactDestination="true" />
<rewrite>
<rules>
<clear />
<rule name="UrlWithPimRewrite" stopProcessing="true">
<match url="/pim.*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<serverVariables>
<set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
<action type="Rewrite" url="http://localhost:1512{R0}" appendQueryString="true" logRewrittenUrl="false" />
</rule>
<rule name="UrlWithoutPIM" enabled="true" stopProcessing="true">
<match url="/*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<serverVariables>
<set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
<action type="Rewrite" url="http://localhost:1512/pim/webaccess" appendQueryString="false" logRewrittenUrl="false" />
</rule>
</rules>
<outboundRules>
<clear />
<rule name="RestoreAcceptEncoding" preCondition="NeedsRestoringAcceptEncoding">
<match serverVariable="HTTP_ACCEPT_ENCODING" pattern="^(.*)" />
<action type="Rewrite" value="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" />
</rule>
<preConditions>
<preCondition name="NeedsRestoringAcceptEncoding">
<add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
<urlCompression doStaticCompression="false" />
</system.webServer>
</configuration>
我发现您使用了
/pim.
作为url匹配部分。但它将只匹配pim/scripts/script.js
url模式。所以你会发现它总是不符合第一条规则
正确的规则如下:
<rule name="UrlWithPimRewrite" stopProcessing="true">
<match url="pim.*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<serverVariables>
<set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
<action type="Rewrite" url="http://localhost:1512{R0}" appendQueryString="true" logRewrittenUrl="false" />
</rule>
@brando zhang
我改变了原来的规则,现在我有下面的配置。最初的一个只是去工作,但其他一切,例如,给了我一个404出于某种原因。有什么想法吗
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpRedirect enabled="false" />
<rewrite>
<rules>
<clear />
<rule name="UrlWithPimRewrite" stopProcessing="true">
<match url="pim.*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{CACHE_URL}" pattern="^(https?)://" />
</conditions>
<serverVariables>
<set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
<action type="Rewrite" url="{C:1}://localhost:1512/{R0}" appendQueryString="true" logRewrittenUrl="false" />
</rule>
<rule name="UrlWithoutPIM" enabled="true" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{URL}" pattern="/pim" negate="true" />
<add input="{CACHE_URL}" pattern="^(https?)://" />
</conditions>
<serverVariables>
<set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
<action type="Rewrite" url="{C:1}://localhost:1512/pim/webaccess" appendQueryString="false" logRewrittenUrl="false" />
</rule>
</rules>
<outboundRules>
<clear />
<rule name="RestoreAcceptEncoding" preCondition="NeedsRestoringAcceptEncoding">
<match serverVariable="HTTP_ACCEPT_ENCODING" pattern="^(.*)" />
<action type="Rewrite" value="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" />
</rule>
<preConditions>
<preCondition name="NeedsRestoringAcceptEncoding">
<add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
<urlCompression doStaticCompression="true" />
<directoryBrowse enabled="false" />
</system.webServer>
</configuration>
FRT怎么说?这只是给了我一个403禁止的回答。你知道为什么吗?你能告诉我你使用了哪个url来面对403错误吗?请看我的新评论。