How to allow utm_source & utm_medium in IIS Rewrite / Reverse Proxy - iis

I have created reverse proxy Windows server 2016 and IIS.
Everything is working fine, but the problem is following it doesnt allow the url like this,
https://mywebsite/shop/product/3231?utm_source=IGShopping&utm_medium=Social
but when I replace utm_source as utm_sour or something then it works fine.
In simple words, with utm_source and utm_medium variables it gives this error.
Screenshot of the error
Directly with the localhost it works fine.
https://mywebsite/shop/product/3231?utm_source=IGShopping&utm_medium=Social
For the reference, my web.config file is as follows
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<outboundRules>
<clear />
<rule name="Add SameSite" preCondition="No SameSite">
<match serverVariable="RESPONSE_Set_Cookie" pattern=".*" negate="false" />
<action type="Rewrite" value="{R:0}; SameSite=None; Secure" />
</rule>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1" enabled="true">
<match filterByTags="A, Form, Img" pattern="^http(s)?://localhost:8068/(.*)" />
<action type="Rewrite" value="http{R:1}://mocauae.ae/{R:2}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
<preCondition name="No SameSite">
<add input="{RESPONSE_Set_Cookie}" pattern="." />
<add input="{RESPONSE_Set_Cookie}" pattern="; SameSite=None; Secure" negate="true" />
</preCondition>
</preConditions>
</outboundRules>
<rules>
<rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://localhost:8068/{R:1}" />
</rule>
<rule name="HTTPS" enabled="false" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="http://localhost:8068" redirectType="Found" />
</rule>
<rule name="HTTPS force" enabled="false" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://localhost:8068" appendQueryString="false" redirectType="Permanent" />
</rule>
<rule name="https pure" enabled="false" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<action type="Redirect" url="https://localhost:8068" redirectType="Found" />
<conditions>
<add input="{HTTP}" pattern="off" />
</conditions>
</rule>
</rules>
</rewrite>
<httpRedirect enabled="false" destination="http://localhost:8068" exactDestination="true" />
</system.webServer>
</configuration>

I the solution by just simply ignoring the url parameter and it worked for me
<rule name="IngnoreUTMSource" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{QUERY_STRING}" pattern="utm_source=.*" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/{R:0}" appendQueryString="false" redirectType="Permanent" />
</rule>

Related

Site not redirecting from www to https

On IIS7, my website is not redirecting from www.example.com to https://example.com
Instead it tries to open https://www.example.com
Here is the web.config file
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="WWW to HTTPS">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example\.com$" negate="true" />
</conditions>
<action type="Redirect" url="https://example.com/{R:1}" />
</rule>
<rule name="HTTP TO HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />
</rule>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="backend-api/(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{URL}" pattern="^/(backend-api)/.*" />
</conditions>
<action type="Rewrite" url="http://localhost:3033/{R:1}" />
</rule>
<rule name="AngularPageRefresh" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
<outboundRules>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>
What am I missing?
You can use the following rule:
<rule name="test1" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.(.+)$" />
</conditions>
<action type="Redirect" url="https://{C:1}" />
</rule>

IIS can't rewrite outbound rule having soket.io query

I am banging my head into the wall. Every single URL is re-written by IIS URL Rewrite module but the response having https://nginx-server/socket.io/?EIO=3&transport=polling&t=1486150196479-0 when I open my Network tab in chrome, I see:
https://nginx-server.com/socket.io/?EIO=3&transport=polling&t=1486150196479-0
https://nginx-server.com/socket.io/?EIO=3&transport=polling&t=1486150196479-0
https://iis-reverse-proxy-server.com/t/assets/images/chat-logo.png
https://iis-reverse-proxy-server.com/config.js
https://iis-reverse-proxy-server.com/t/assets/images/main_logo.png
I am trying to reverse proxy the https://nginx-server. IIS reverse proxy rewrite all the URL that are accessing nginx except those having socket.io URI in them . Same thing happens when some api is called and the IIS just stop rewriting outbound rules.
this is my web.config.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
<match url="^(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{CACHE_URL}" pattern="^(https?)://" />
</conditions>
<serverVariables>
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
<action type="Rewrite" url="{C:1}://nginx-server.com/{R:0}" />
</rule>
</rules>
<outboundRules>
<clear />
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1" stopProcessing="true">
<match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^(.*)?://nginx-server.com/(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true" />
<action type="Rewrite" value="{R:1}://iis-reverse-proxy-server.com/{R:2}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/(.+)" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
</system.webServer>
</configuration>
==========Edit:===========
This is my updated web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
<match url="^(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{CACHE_URL}" pattern="^(https?)://" />
</conditions>
<serverVariables>
<set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="HTTP_ACCEPT_ENCODING" />
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
<action type="Rewrite" url="{C:1}://nginx-server.com/{R:0}" />
</rule>
</rules>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1" stopProcessing="true">
<match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^(.*)?://nginx-server.com/(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true" />
<action type="Rewrite" value="{R:1}://iis-reverse-proxy-server.com/{R:2}" />
</rule>
<rule name="RestoreAcceptEncoding" preCondition="NeedsRestoringAcceptEncoding">
<match serverVariable="HTTP_ACCEPT_ENCODING" pattern="^(.*)" />
<action type="Rewrite" value="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" />
</rule>
<rule name="Atag" preCondition="ResponseIsHtml1">
<match pattern="href=(.*?)https://nginx-server.com/(.*?)\s" />
<action type="Rewrite" value="href={R:1}https://iis-reverse-proxy-server.expertflow.com/{R:2}" />
</rule>
<rule name="elementencodedaction" preCondition="ResponseIsHtml1">
<match pattern="action=(.*?)https://nginx-server.com/(.*?)\\" />
<action type="Rewrite" value="‘action={R:1}https://iis-reverse-proxy-server.expertflow.com/{R:2}\" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/(.+)" />
</preCondition>
<preCondition name="NeedsRestoringAcceptEncoding">
<add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>
Where am I making mistake?
Thanks everyone for the efforts for intended help. It turned out the config file in the application re writing the URL so that is why IIS could not be able to rewrite the URL. Updating URL in config file resolved my issue.

Redirection to (https and non www) for all requested URI via web.config

I want ( https and non www) redirection for all requested URI. Any help would be highly appreciated. Thanks,
It works well for
1) 'http' to 'https' (success)
2) 'https' to 'https' (success)
3) '/index' to '/'
4) '/contact (with www)' to '/contact (with non www)' (unsuccess)
<system.web>
<customErrors mode="On" defaultRedirect="/" >
<error statusCode="404" redirect="/" />
</customErrors>
</system.web>
<system.webServer>
<rewrite>
<rewriteMaps>
<rewriteMap name="Redirects">
<add key="/index.php" value="/" />
<add key="/a.php" value="/a" />
<add key="/Res" value="/results#experience" />
<add key="/blog/" value="/" />
</rewriteMap>
</rewriteMaps>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}.php" matchType="IsFile" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="{R:1}.php" appendQueryString="true" />
</rule>
<rule name="Redirect rule1 for Redirects">
<match url=".*" />
<conditions>
<add input="{Redirects:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
<rule name="Remove www prefix">
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://test.com.au/{R:1}" redirectType="Permanent"/>
</rule>
<rule name="Redirect index.php" stopProcessing="true">
<match url="^(\w*/)?index\.php" ignoreCase="true"></match>
<conditions>
<add input="{HTTP_HOST}" pattern="test\.com\.au$"/>
</conditions>
<action type="Redirect" url="https://test.com.au/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
<staticContent>
<clientCache cacheControlCustom="public" cacheControlMode="UseExpires" httpExpires="Tue,19 Jan 2038 03:14:07 GMT" />
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
<mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
</staticContent>
<defaultDocument>
<files>
<remove value="index.php" />
<add value="index.php" />
</files>
</defaultDocument>
</system.webServer>
I want all requested uri to redirect to https and non www via web.config only
Refer to the code as below:
<rewrite>
<rules>
<rule name="Redirect to non-www" stopProcessing="true">
<match url="(.*)" negate="false"></match>
<action type="Redirect" url="https://example.com/{R:1}"></action>
<conditions>
<add input="{HTTP_HOST}" pattern="^example\.com$" negate="true"></add>
</conditions>
</rule>
</rules>
</rewrite>

How to customize redirecting http to https on IIS8.5

I need to redirect http to https on external network (internet), but on local network such as 192.168.1.100 works on http. I used this following configuration:
<system.webServer>
<rewrite>
<rules>
<rule name="HTTPS force" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
You can add an additional condition "host shouldn't match 192.168.1.100".
Your rule should be like that:
<rule name="HTTPS force" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{HTTP_HOST}" pattern="^192.168.1.100$" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>

IIS7 URL rewrite rules makes friendly url recursive

I have a site done in asp and url rewritten rules from a db provider. I works fine but I have an annoying issue I've not been able to solve correctly.
The rewritten rules work as follows:
www.mydomain.com/default.asp --> www.mydomain.com/lang
www.mydomain.com/content.asp?id=1 --> www.mydomain.com/lang/category-title
www.mydomain.com/content.asp?id=1&ref=2 --> www.mydomain.com/lang/category-title/content-title
The rules are:
<rules>
<clear />
<rule name="dbp_Redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{DB:{R:1}?{QUERY_STRING}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" logRewrittenUrl="false" />
</rule>
<rule name="dbp_Reverse" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{DB_rewrite:{R:1}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="{C:1}" logRewrittenUrl="false" />
</rule>
</rules>
<outboundRules>
<clear />
<rule name="Outbounddbp_Reverse" preCondition="ResponseIsHtml1" enabled="true">
<match filterByTags="A" pattern="^(.*/)(.*)" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{DB_outbound:{R:2}}" matchType="Pattern" pattern="(.+)" ignoreCase="true" negate="false" />
</conditions>
<action type="Rewrite" value="{C:0}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
The problem is that when the user gets to
www.mydomain.com/lang/category-title/content-title
page all the links rewritten in this page goes like this:
www.mydomain.com/lang/category-title/content-title/*lang/category-title/content-title*
(as you can see the "lang/category-title/content-title" is repeated twice)
Sure I'm missing something in the rules but I cannot see what it is.
Any help would be appreciated.

Resources