Url 当查询值中有正斜杠时重写不起作用
Url rewrite not working when there are forward slashes inside the query value
我有一个原始的 URL 看起来像这样:
https://example.com/?page=map&path=Video's
我在 IIS 管理器中创建了一个规则,上面重写为
http://h2609709.stratoserver.net/map/Video's/
这很好用。
然而,当原来的URL是这样的:
https://example.com/?page=map&path=Video's/birthday/2016
它被正确重写为:
https://example.com/map/Video's/birthday/2016/
但该页面导致错误 404。如何让服务器将 &path=Video's/birthday/2016
解释为 查询 值而不是远程文件夹路径?
问题是由查询字符串中的 /
字符引起的。
Web.config
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^page=([^=&]+)&path=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}/{C:2}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^([^/]+)/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="?page={R:1}&path={R:2}" />
</rule>
看起来像你需要的:
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^([^/]+)/(.*)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="?page={R:1}&path={R:2}" />
</rule>
我更改了正则表达式。现在 {R:1}
是斜杠之间的第一个单词,{R:2}
是
之后的所有内容
我有一个原始的 URL 看起来像这样:
https://example.com/?page=map&path=Video's
我在 IIS 管理器中创建了一个规则,上面重写为
http://h2609709.stratoserver.net/map/Video's/
这很好用。
然而,当原来的URL是这样的:
https://example.com/?page=map&path=Video's/birthday/2016
它被正确重写为:
https://example.com/map/Video's/birthday/2016/
但该页面导致错误 404。如何让服务器将 &path=Video's/birthday/2016
解释为 查询 值而不是远程文件夹路径?
问题是由查询字符串中的 /
字符引起的。
Web.config
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^page=([^=&]+)&path=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}/{C:2}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^([^/]+)/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="?page={R:1}&path={R:2}" />
</rule>
看起来像你需要的:
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^([^/]+)/(.*)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="?page={R:1}&path={R:2}" />
</rule>
我更改了正则表达式。现在 {R:1}
是斜杠之间的第一个单词,{R:2}
是