简体   繁体   中英

IIS rewrite how to intercept a set cookie value

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Rewrite requests" enabled="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="https://site1.domain1.net/{R:0}" />
                </rule>
            </rules>
            <outboundRules>
                <rule name="Rewrite outbound" enabled="true">
                    <match filterByTags="None" pattern="(.*)site1\.domain1\.net(.*)" />
                    <action type="Rewrite" value="{R:1}site2.domain2.com{R:2}" />
                </rule>
                <rule name="Rewrite cookie">
                    <match serverVariable="{HTTP_COOKIE}" pattern="(.*)site1\.domain1\.net(.*)" />
                    <action type="Rewrite" value="{R:1}site2.domain2.com{R:2}" />
                </rule>
                <preConditions>
                </preConditions>
            </outboundRules>
        </rewrite>
    </system.webServer>
</configuration>

Ok so I have a frontend server which is accessed by site2.domain2.com and all traffic to it should be url rewrote as site1.domain1.net this works pretty easily. My problem is the site running on site1.domain1.net writes a cookie with a bunch of non-standard values for the application it runs. I need to be able to change a value written to the cookie for logon purposes.

The line I need to target is below

https%3a%2f%2fsite1.domain1.net%2flgn%2fauth2%2fagent%2fsrms%2frefresh

It doesn't have any standard tag like url=value or host=value it's just the line above, I need to catch the site1.domain1.net part and change to site2.domain2.com but not having much luck.

You can see in the code at the top where I tried to do this, unsuccessfully as I don't know much about playing with the cookies. Suggestions?

I was close but wasn't using the right stuff, though a bunch more trial and error I managed to figure it out.

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="Rewrite requests" enabled="true">
                        <match url="(.*)" />
                        <action type="Rewrite" url="https://site1.domain1.net/{R:0}" />
                    </rule>
                </rules>
                <outboundRules>
                    <rule name="Rewrite outbound" enabled="true">
                        <match filterByTags="None" pattern="(.*)site1\.domain1\.net(.*)" />
                        <action type="Rewrite" value="{R:1}site2.domain2.com{R:2}" />
                    </rule>
                    <rule name="Modify Cookie">
                    <match serverVariable="RESPONSE_Set_Cookie" pattern=".*" />
                    <conditions>
                            <add input="{R:0}" pattern="(.*)site1\.domain1\.net(.*)" />
                    </conditions>
                    <action type="Rewrite" value="{C:1}site2.domain2.com{C:2}" />
                </rule>
                </outboundRules>
            </rewrite>
        </system.webServer>
    </configuration>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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