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>
Related
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>
How can we combine these two rules for IIS?
"mod_rewrite" - redirects all requests to the PHP script to index.php
The second is a classic redirect from http to https
But the trouble is that either one or the other works, the two rules do not work together, tell me how to combine them?
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="index.php" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="Silex Front Controller" enabled="true" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
<rule name="http-to-https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
You could implement both of the rule at same time. you just need to change the order of the rule. place the https redirect rule at first:
<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}/{R:1}" redirectType="Found" />
</rule>
<rule name="Silex Front Controller" enabled="true" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
I need to redirect the user every time he enters subdomain.mywebsite.com to subdomain.mywebsite.com/app
I tried to do the following
<rewrite>
<rules>
<rule name="MyRule" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^subdomain.mywebsite.com$" />
</conditions>
<action type="Redirect" url="https://subdomain.mywebsite.com/app" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
But it gives me 'redirect multiple times' error
Please advice
UPD: I also need it to work for https
https://subdomain.mywebsite.com
So every time the user opens subdomain.mywebsite.com with HTTP or HTTPS it should forward to https://subdomain.mywebsite.com/app
That's because your rule also works for https://subdomain.mywebsite.com/. So it keep redirecting to itself.
Please add a condition pattern {HTTPS}=off to only redirect http request.
<rule name="MyRule" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^subdomain.mywebsite.com$" />
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://subdomain.mywebsite.com/app" redirectType="Permanent" />
</rule>
5/7Edit:
Please try this rule
<rule name="MyRule" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^subdomain.mywebsite.com$" />
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" url="https://subdomain.mywebsite.com/app" redirectType="Permanent" />
</rule>
<rule name="My Rule2" enabled="true" stopProcessing="true">
<match url="^app(/)?$" negate="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^subdomain.mywebsite.com$" />
<add input="{HTTPS}" pattern="^on$" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" url="https://subdomain.mywebsite.com/app" />
</rule>
<rule name="MyRule3" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^off$" />
<add input="{HTTP_HOST}" pattern="^subdomain.mywebsite.com$" />
</conditions>
<action type="Redirect" url="https://subdomain.mywebsite.com{REQUEST_URI}" />
</rule>
I would like to use part of the filename as a folder name, my redirect is working but the rewrite does not work, this is my web.config (also has a rule to remove the file extension):
Original: https://www.ipressnet.com.br/v6/client_tracking.aspx?id=x
Rewrite: https://www.ipressnet.com.br/v6/client/tracking?id=x
THIS WORKS:
<rule name="RemoveASPx" enabled="true" stopProcessing="false">
<match url="(.*)\.aspx" />
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>
<rule name="AddASPx" enabled="true">
<match url=".*" negate="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="{R:0}.aspx" />
</rule>
THIS DOES NOT WORK:
<rule name="RemoveClient" enabled="true" stopProcessing="false">
<match url="^v6/?$|^client_(.*)$" />
<action type="Redirect" url="client/{R:1}" />
</rule>
<rule name="AddClient" enabled="true">
<match url="^v6/client/(.*)$" negate="false" />
<action type="Rewrite" url="v6/client_{R:1}.aspx" />
</rule>
I appreciate any help, thank you!
You can write RemoveASPx and RemoveClient in the same rule.
The following rule maybe achieve your requirement.
<rule name="rewrite rule" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{URL}" pattern="^/v6(.*)client_(.*)\.aspx$" />
</conditions>
<action type="Redirect" url="v6{C:1}client/{C:2}" redirectType="Temporary" />
</rule>
<rule name="(.*)" enabled="false">
<match url="(.*)" />
<conditions>
<add input="{URL}" pattern="^/v6/client/(.*)" />
</conditions>
<action type="Rewrite" url="v6/client_{C:1}.aspx" />
</rule>
<rule name="r1" stopProcessing="true">
<match url="v6/(client)?(_)?(.*).aspx" ignoreCase="false" />
<action type="Rewrite" url="v6/{R:1}/{R:3}" />
</rule>
I have a number of URL rewrite rules in place (they are all listed below). When I browse "http://domain.com" I am forwarded to "http://www.domain.com/R:" with the message of "A potentially dangerous Request.Path value was detected from the client (:)." I want to be able to browse the site without "www" and be forwarded correctly. I am not sure how to update or add to my existing rewrite rules. This is .Net site. I am hoping someone in the community can give me any hints.
<rewrite>
<rules>
<clear />
<rule name="Change to Lower" enabled="true">
<match url="[A-Z]" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Redirect" url="{ToLower:{URL}}" redirectType="Permanent" />
</rule>
<rule name="Redirect to WWW" enabled="true" stopProcessing="true">
<match url=".*" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^domain.com$" />
</conditions>
<action type="Redirect" url="http://www.domain.com/R:{0}" redirectType="Permanent" />
</rule>
<rule name="Redirect StockNo" stopProcessing="true">
<match url="^vehicles/detail/default\.aspx$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^stockno=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
<rule name="Rewrite StockNo" stopProcessing="true">
<match url="^([0-9a-z\ ]+)$" />
<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="vehicles/detail/default.aspx?stockno={R:1}" />
</rule>
<rule name="Redirect StockNo And Desc" enabled="false" stopProcessing="true">
<match url="^vehicles/detail/default\.aspx$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^stockno=([^=&]+)&desc=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}/{C:2}" appendQueryString="false" />
</rule>
<rule name="Rewrite StockNo And Desc" enabled="false" stopProcessing="true">
<match url="^([0-9a-z]+)/([0-9]{4}[^/]+)/?$" />
<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="vehicles/detail/default.aspx?stockno={R:1}&desc={R:2}" />
</rule>
<rule name="Redirect StockNo Desc And Vin" stopProcessing="true">
<match url="^vehicles/detail/default\.aspx$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^stockno=([^=&]+)&desc=([^=&]+)&vin=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}/{C:2}/{C:3}" appendQueryString="false" />
</rule>
<rule name="Rewrite StockNo Desc And Vin" stopProcessing="true">
<match url="^([0-9a-z]+)/([0-9]{4}[^/]+)/([0-9a-z]+)/?$" />
<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="vehicles/detail/default.aspx?stockno={R:1}&desc={R:2}&vin={R:3}" />
</rule>
<rule name="Redirect Make And Model" stopProcessing="true">
<match url="^vehicles/default\.aspx$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^make=([^=&]+)&model=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}/{C:2}" appendQueryString="false" />
</rule>
<rule name="Rewrite Make And Model" stopProcessing="true">
<match url="^([a-z\ ]+)/([a-z\ ]+)/?$" />
<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="vehicles/default.aspx?make={R:1}&model={R:2}" />
</rule>
<rule name="Redirect Make Model And SubModel" stopProcessing="true">
<match url="^vehicles/default\.aspx$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^make=([^=&]+)&model=([^=&]+)&submodel=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}/{C:2}/{C:3}" appendQueryString="false" />
</rule>
<rule name="Rewrite Make Model And SubModel" stopProcessing="true">
<match url="^([a-z\ ]+)/([a-z\ ]+)/([a-z\ ]+)/?$" />
<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="vehicles/default.aspx?make={R:1}&model={R:2}&submodel={R:3}" />
</rule>
<rule name="Redirect Make An Offer StockNo" stopProcessing="true">
<match url="^Vehicles/Make-An-Offer\.aspx$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^stockno=([^=&]+)$" />
</conditions>
<action type="Redirect" url="Vehicles/Make-An-Offer/{C:1}" appendQueryString="false" />
</rule>
<rule name="Rewrite Make An Offer StockNo" stopProcessing="true">
<match url="^Vehicles/Make-An-Offer/([^/]+)/?$" />
<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="Vehicles/Make-An-Offer.aspx?stockno={R:1}" />
</rule>
<rule name="Redirect Make An Offer StockNo And Desc" stopProcessing="true">
<match url="^Vehicles/Make-An-Offer\.aspx$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^stockno=([^=&]+)&desc=([^=&]+)$" />
</conditions>
<action type="Redirect" url="Vehicles/Make-An-Offer/{C:1}/{C:2}" appendQueryString="false" />
</rule>
<rule name="Rewrite Make An Offer StockNo And Desc" stopProcessing="true">
<match url="^Vehicles/Make-An-Offer/([^/]+)/([^/]+)/?$" />
<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="Vehicles/Make-An-Offer.aspx?stockno={R:1}&desc={R:2}" />
</rule>
<rule name="Redirect to Default" enabled="true">
<match url="(.*)default.aspx" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>
<rule name="Add Trailing Slash" enabled="true">
<match url="[^/]$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{URL}" pattern="\.axd$" ignoreCase="false" negate="true" />
</conditions>
<action type="Redirect" url="{URL}/" appendQueryString="false" redirectType="Permanent" />
</rule>
</rules>
<outboundRules>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
<rewriteMaps>
<rewriteMap name="test" />
</rewriteMaps>
In your 2nd rule, it looks like the R: is not enclosed in brackets:
http://www.domain.com/R:{0} should be http://www.domain.com/{R:0}