简体   繁体   English

重定向规则iis 7 URL重写的可选参数

[英]optional parameters for redirect rule iis 7 url rewriting

How can I do a Redirect Rule that transforms this URL: 我该如何做一个转换此URL的重定向规则:

http://localhost/app/Company/HomePage.aspx?COMPANYID=2&FORCESHOWCASE=TRUE&THEMEPREVIEW=3

to this one: 对此:

http://localhost/app/2/showcase/preview/3

But the trick here is that all the parameters are optional except the COMPANYID, so the url can be: 但是这里的技巧是,除了COMPANYID之外,所有参数都是可选的,因此url可以是:

http://localhost/app/2/preview/3

or: 要么:

http://localhost/app/2/showcase

I have not been able to find the right redirect rule to match this pattern. 我无法找到正确的重定向规则来匹配此模式。 I've tried the following: 我尝试了以下方法:

<rule name="RedirectUserFriendlyURLCompany" stopProcessing="true">
                    <match url="^Company/HomePage\.aspx$" />
                    <conditions>
                        <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
                        <add input="{QUERY_STRING}" pattern="^COMPANYID=([^=&amp;]+)(&amp;FORCESHOWCASE=([^=&amp;]+))?(&amp;THEMEPREVIEW=([^=&amp;]+))?$" />
                    </conditions>
                    <action type="Redirect" url="{C:1}" appendQueryString="false" />
                </rule>
                <rule name="RewriteUserFriendlyURLCompany" stopProcessing="true">
                    <match url="^([A-Za-z0-9]+)/?([A-Za-z0-9]*)(/preview/([A-Za-z0-9]*))?/?$" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="Company/HomePage.aspx?COMPANYID={R:1}&amp;FORCESHOWCASE={R:2}&amp;THEMEPREVIEW={R:4}" />
                </rule>

The Rewrite rule recognizes if I put some parameters or all of them and works great, if I try with any of the urls from above it rewrites it to the right url with the right parameters, but the problem is with the redirect rule, it doesn't work at all, if I put in the browser: 重写规则可以识别出是否放置了一些参数或所有参数,并且效果很好,如果我尝试从上方尝试使用任何网址,它都会使用正确的参数将其重写为正确的网址,但是问题在于重定向规则,它没有如果我安装在浏览器中,则根本无法工作:

http://localhost/app/Company/HomePage.aspx?COMPANYID=2&FORCESHOWCASE=TRUE&THEMEPREVIEW=3

it doesn't redirect to the correct page and I dont know what to do, please help! 它没有重定向到正确的页面,我不知道该怎么办,请帮忙! Sorry for my English and thanks in advance 对不起,我的英语,请先谢谢

As nobody answered my question, it seems that theres no "easy" answer. 由于没有人回答我的问题,因此似乎没有“简单”的答案。

The way I make this work was changing my rules, using session variables instead of querystring 我进行这项工作的方式是使用会话变量而不是querystring更改规则。

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

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