Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, December 4, 2018 7:23 PM
Hello,
I am attempting to use URL Rewrite to simply change out the domain name of my site, keeping the entirety of the requested path, including the query string, untouched. It seems simple, considering that there is the option to "append query string", yet all responses from this IIS server do not include the query string.
<rewrite>
<rules>
<rule name="Subdomain Redirection" stopProcessing="true">
<match url="(.*)" />
<action type="Redirect" url="https://new.domain.com/{R:0}" appendQueryString="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="old.domain.com" />
</conditions>
</rule>
</rules>
</rewrite>
Clients attempting to access the url https://old.domain.com/app/login?id=648215 are being redirected to https://new.domain.com/app/login missing the query string. What am I missing?
All replies (3)
Wednesday, December 5, 2018 9:45 AM âś…Answered
Hi jbparrish,
Normally, we could use codition to achieve your requirement.By matching the conditions against the {QUERY_STRING} you can use back references to use them in the redirect URL.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect" stopProcessing="true">
<match url="(.*)" />
<conditions trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="&?(id=[^&]+)&?" />
<add input="{HTTP_HOST}" pattern="old.domain.com" />
</conditions>
<action type="Redirect" url="https://new.domain.com/?{C:1}" appendQueryString="false" redirectType="Found" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Best Regards,
Brando
Tuesday, December 4, 2018 10:16 PM
all responses from this IIS server do not include the query string.
IIS URL Rewrite module only takes care of requests, not responses as the rules you wrote are inbound rules.
Wednesday, December 5, 2018 8:48 PM
Thank you very much. I also included a condition for {PATH_INFO} to filter requests to that specific URL path, then followed your advice and regex to use a condition for the query string to capture it and put it in the rewrite. Worked great! Thank you!