How to add multiple URL rewrite rules in a web.config
I want to match any url that contains "sales" and "registrationsuccess".
I get errors with when I try the following:
<rewrite>
<rules>
<rule name="Redirect HTTP to HTTPS" stopProcessing="true">
<match url="(.*sales*)"/>
<match url="(.*registrationsuccess*)"/>
<conditions>
<add input="{HTTPS}" pattern="^OFF$"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther"/>
</rule>
</rules>
</rewrite>
This is how you add more than one rule:
<rewrite>
<rules>
<rule name="Redirect HTTP to HTTPS (Sales)" stopProcessing="true">
<match url="(.*sales*)"/>
<conditions>
<add input="{HTTPS}" pattern="^OFF$"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther"/>
</rule>
<rule name="Redirect HTTP to HTTPS (RegistrationSucces)" stopProcessing="true">
<match url="(.*registrationsuccess*)"/>
<conditions>
<add input="{HTTPS}" pattern="^OFF$"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther"/>
</rule>
</rules>
</rewrite>
But for what you're trying to do, you can do it with one rule, like below:
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="ON" />
<add input="{PATH_INFO}" pattern="^(.*)/sales/(.*)" />
<add input="{PATH_INFO}" pattern="^(.*)/registrationsuccess/(.*)" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
Related
I have my first IIS Server set up and running. And I have successfully configured the URL Rewrite add on. It works perfectly for all incoming requests. How ever I want to exclude one additional website that runs on the same IIS server. Can someone teach me how to do this?
web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="^(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<serverVariables>
<set name="HTTP_REFERER" value="{HTTP_ACCEPT_ENCODING}" />
<set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
<action type="Rewrite" url="http://working.backendserver:4588/{R:1}" />
</rule>
</rules>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Base, Form, Img" pattern="^http(s)?://working.backendserver:4588/(.*)" />
<action type="Rewrite" value="http{R:1}://working.inbound.url.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>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
<preCondition name="NeedsRestoringAcceptEncoding">
<add input="{RESPONSE_CONTENT_TYPE}" pattern=".+" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>
enter code here
I'm tryin to force my website to only accept https, by adding the following to my webconfig:
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
This works, if you load the site using http it now re-directs the site to https, but every time I try to go to a different page or submit a form I get a:
405 - HTTP verb used to access this page is not allowed.
This currentle my webconfi:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="PW_BADPOST" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{REQUEST_METHOD}" matchType="Pattern" pattern="POST" ignoreCase="true" />
<add input="{HTTP_REFERER}" pattern=".*\/wp-admin.*" />
</conditions>
<action type="CustomResponse" statusCode="404"/>
</rule>
<rule name="PW_BadURL" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_URI}" pattern="\.php" />
<add input="{REQUEST_URI}" pattern="die\(" />
<add input="{REQUEST_URI}" pattern="connector\.asp" />
</conditions>
<action type="CustomResponse" statusCode="404"/>
</rule>
<!-- directories to ignore -->
<rule name="PW_IgnoreDir" stopProcessing="true">
<match url="^(css|img|images|js|tools)\/(.*)$" ignoreCase="true" />
<action type="None" />
</rule>
<!-- Pages -->
<rule name="PW_Pages" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?{R:1}" />
</rule>
</rules>
</rewrite>
<directoryBrowse enabled="false" />
</system.webServer>
</configuration>
I want to rewrite this URL
https://www.website.com/parameter-1?query=100345046
To this
https://www.website.com/parameter?query=100345046
Basically I want the -1 removed from the URL.
I made an example which works, using RegExr, but I don't know how to implement this using the IIS.
So far I made this rule but I can't get the query part after the -1 to stick the to rewrote URL.
<rule name="Redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_URI}" pattern="^/parameter-1$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/parameter" appendQueryString="true" />
</rule>
Alright I figured it out.
<rule name="Redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_URI}" pattern="/parameter-1\?query=(.*)$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/parameter?" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="WC2018" stopProcessing="true">
<match url="^product/sb/sales.htm" />
<action type="Rewrite" url="product/sb/market/sales.htm" />
</rule>
Above is the url rewrite that i do, the original link is
product/sb/sales.htm
I need to rewrite it to
product/sb/market/sales.htm
But it does not work. I not sure what went wrong.
You can try this rules :
<rule name="rule 1k" stopProcessing="true">
<match url="^product/sb/market/sales.htm$" ignoreCase="true" />
<action type="Rewrite" url="/product/sb/sales.htm" />
</rule>
I have a new site https://www.NewSite.com and I would like all the traffic to my old site https://www.OldSite.com to be redirected to the root of my new site https://www.NewSite.com/, with some exception.
For instance I would like the URL (among others) https://www.OldSite.com/noredirect not to be redirected and others to be rewritten. For instance:
https://www.OldSite.com -> https://www.NewSite.com/
https://www.OldSite.com/library->https://www.NewSite.com/
https://www.OldSite.com/kb/ -> https://www.newsite.com/kb
https://www.OldSite.com/kb/articles.aspx?id=45 -> https://www.NewSite.com/kb
https://www.OldSite.com/noredirect -> https://www.oldsite.com/noredirect
https://www.OldSite.com/noredirect/page.aspx -> https://www.oldsite.com/noredirect/page.aspx
Therefore I wrote two rules in my Old Site site in IIS:
<rewrite>
<rules>
<clear />
<rule name="Rewrite To New Site" stopProcessing="true">
<match url="/kb(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="https://www.newsite.com/kb" />
</rule>
<rule name="Redirect to New Site" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_URI}" pattern="(.*)/noredirect$" negate="true" />
</conditions>
<action type="Redirect" url="https://www.newsite.com" appendQueryString="false" />
</rule>
</rules>
</rewrite>
This rules just redirect all the requests to my old site to the root of my new site, ignoring the exceptions and the rewrite rule. The same happens with:
<rule name="Redirect to New Site" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_URI}" pattern="^/noredirect(.*)" negate="true" />
</conditions>
<action type="Redirect" url="https://www.newsite.com" appendQueryString="false" />
</rule>
What am I doing wrong?
Make sure you've checked "Enable proxy" under Application Request Routing cache.
You can find some information about it here:
http://www.iis.net/learn/extensions/configuring-application-request-routing-%28arr%29/creating-a-forward-proxy-using-application-request-routing
Good luck!