IIS rewrite to add a query variable to every request

I know next to nothing about configuring IIS, but have been assigned a task to add a query variable to every request that is made through an IIS server that's being used as a Web proxy.

We look for any URL where the first path segment after the domain is a fixed string, like /bongo/ and redirect that to a back end server. I have it working to perform redirects, but I'm pretty sure I have a lot of garbage that I don't need in the following config, which I got from another answer.

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
        <rewrite> 
            <rules> 
                <rule name="Route the requests for bongo Player" stopProcessing="true"> 
                    <match url="^bongo/(.*)" /> 
                    <conditions> 
                        <add input="{CACHE_URL}" pattern="^(https?)://" /> 
                    </conditions> 
                    <action type="Rewrite" url="https://bongo.fse.companyinc.com/bongo/{R:1}" /> 
                    <serverVariables> 
                        <set name="HTTP_ACCEPT_ENCODING" value="" /> 
                    </serverVariables> 
                </rule> 
            </rules> 
            <outboundRules> 
                <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1"> 
                    <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^http(s)?://bongo.fse.companyinc.com/bongo/(.*)" /> 
                    <action type="Rewrite" value="/{R:2}" /> 
                </rule> 
                <rule name="RewriteRelativePaths" preCondition="ResponseIsHtml1"> 
                    <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^/bongo/(.*)" negate="false" /> 
                    <action type="Rewrite" value="/{R:1}" /> 
                </rule> 
                <preConditions> 
                    <preCondition name="ResponseIsHtml1"> 
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" /> 
                    </preCondition> 
                </preConditions> 
            </outboundRules> 
        </rewrite>
        <tracing>
            <traceFailedRequests>
                <add path="*">
                    <traceAreas>
                        <add provider="ASP" verbosity="Verbose" />
                        <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
                        <add provider="ISAPI Extension" verbosity="Verbose" />
                        <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI,WebSocket,Rewrite,RequestRouting" verbosity="Verbose" />
                    </traceAreas>
                    <failureDefinitions timeTaken="00:00:30" statusCodes="200-299,300-399,400-499,500-599" verbosity="Warning" />
                </add>
            </traceFailedRequests>
        </tracing> 
    </system.webServer> 
</configuration>

1) I'm not even sure that I need the outbound rules.

2) The main problem that I have is that I want to always append a query variable, whether there are existing query variables or not. I've tried too many configurations to list here, but I can't seem to always get it to append the variable when proxying. Also, I think there needs to be some sort of conditional that does something different if there are already arguments or if the one to be added is the only one.

I'd appreciate help from any IIS gurus out there.

0
задан 18 April 2018 в 18:39
1 ответ

Собственно, решил это. Это был кусок пирога.Проблема в том, что мы предполагали, что IIS добавит существующую строку запроса, поэтому мы попробовали:

<action type="Rewrite" url="https://bingo.lms.bingoinc.com/bingo/{R:1}&abc=asd23242" /> 

На самом деле, достаточно умен, чтобы проверить, есть ли уже знак '?' и добавляет исходные переменные запроса в конец, так что это работает:

<action type="Rewrite" url="bingo.lms.bingoinc.com/bingo{R:1}?abc=asd23242" />
0
ответ дан 5 December 2019 в 06:10

Теги

Похожие вопросы