URL重写不工作的时候有斜杠查询值

问题描述:

我有一个看起来喜欢这样的原始URL里面: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=([^=&amp;]+)&amp;path=([^=&amp;]+)$" /> 
    </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}&amp;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}&amp;path={R:2}" /> 
</rule> 

我改变了正则表达式。现在{R:1}是斜杠之间的第一个字。{R:2}就是之后的所有内容

+0

好的,谢谢。我今天晚些时候尝试。我回到你身边。 – Red

+0

工作,谢谢! – Red