I have this simple rewrite, yet for some reason I cannot work out why it's not working:
<system.webServer>
<rewrite>
<rules>
<rule name="men-s-watches" stopProcessing="true">
<match url="(.*)/men-s-watches(.*)" />
<action type="Redirect" url="{R:1}/mens-watches" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
Hopefully someone can point out my noob mistake.
Normally in IIS7 url rewrite module is used and you can assign rules like this.
<system.webServer>
<rewrite>
<rewriteMaps>
<rewriteMap name="usr_rule">
</rewriteMap>
</rewriteMaps>
<rules>
<rule name="men-s-watches">
<match url="^([0-9]+)/men-s-watches/([0-9]+)" />
<action type="Rewrite" url="men-s-watches/default.aspx?id={R:1}&p={R:2}" />
</rule>
</rules>
</rewrite>
</system.webServer>
Related
before i start, i tried the search bar and i saw posts but these didnt really help me.
So im currently trying to foward my domain to force HTTPS and www.
so like when i type mydomain.de it forwards me to https://www.mydomain.de
this is my web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="http to https secure" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{HTTP_HOST}" pattern="^(www.)?speargaming.de" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I dont see what i did wrong there.
I have this rule in web.config in the root of website which redirects to HTTPS:
<rewrite>
<rules>
<rule name="HTTPS" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" negate="false" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
In a subfolder I have separate Config file and I want to clear redirectiong to HTTPS but this folder also redirects to HTTPS:
<rewrite>
<rules>
<clear />
</rules>
</rewrite>
You cannot do that. Rules can be stored defined in web.config only. You can have them there or provided a path to the file where the rules are stored (but it's still defined in the web.config) like this:
<system.webServer>
<rewrite>
<rules configSource="App_Config\RewriteRules.config" />
<outboundRules configSource="App_Config\OutboundRewriteRules.config" />
<rewriteMaps configSource="App_Config\RewriteMaps.config" />
</rewrite>
</system.webServer>
If you want certain URLs not to be redirected to HTTPS then you need to create a smart rule which will detect this (or have set of rules).
<?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>
In IIS 7, I want to force all pages to go to https by adding the following to my web.config but this causes infinite loop.
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" enabled="true" 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>
</rules>
</rewrite>
I have tried to disable rule on all virtual directories/application as suggested here, http://blogs.msdn.com/b/kaushal/archive/2013/05/23/http-to-https-redirects-on-iis-7-x-and-higher.aspx, with no luck. Does anyone have any idea why? Thank you!
How can I configure Intelligencia.UrlRewriter in my ASP.NET web.config file to redirect all http://www.domain.com traffic to http://domain.com?
<if header="host" match="www.yoursite.com" />
<redirect url="^(.+)$" to="http://yoursite.com$1" />
</if>
Thanks, dana, but here's what I ended up adding to my web.config file...
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.mysite.com$" />
</conditions>
<action type="Redirect" url="http://mysite.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>