I have similar urls. But I don`t know how write one rule for my situation.
<rule name="stage">
<match url="stage.some.com/test/docs/overview.htm" />
<action type="Redirect" url="https://stage-docs.some.com/" appendQueryString="false" redirectType="Permanent" />
</rule>
<rule name="prod">
<match url="some.com/test/docs/overview.htm" />
<action type="Redirect" url="https://docs.some.com/" appendQueryString="false" redirectType="Permanent" />
</rule>
First rule has in domain stage.
Any help would be greatly appreciated.
Related
I have rule:
<rule name="main" stopProcessing="true">
<match url="main/([^.]*)/$" />
<action type="Redirect" url="/main/" appendQueryString="false" redirectType="Permanent" />
</rule>
References /main/xxxx/ go to /main/, but I need make rule with one reference (/main/docs/) whitch doesn`t have redirect.
Help me please make exception in rule
References /main/xxxx/ go to /main/, but I need make rule with one reference (/main/docs/) whitch doesn`t have redirect.
To achieve the requirement, you can try to add a condition to the rule, like below.
<rule name="main" stopProcessing="true">
<match url="main/([^.]*)/$" />
<conditions>
<add input="{REQUEST_URI}" pattern="main/doc/" negate="true" />
</conditions>
<action type="Redirect" url="/main/" appendQueryString="false" redirectType="Permanent" />
</rule>
I want to rewrite all images to a different folder. I'm using IIS and have configured a rule in the web.config to redirect all requests to a node.js file as follows:
<rewrite>
<rules>
<rule name="img">
<match url="\/(.*).img" />
<action type="Rewrite" url="/handlers/img.js" />
</rule>
</rules>
</rewrite>
All requests are now being sent to the img.js file, where based on a condition, I want to redirect to another image file. But IIS now sends that file to the img.js and it ends up as a loop. Is there any way out of this loop?
You could try the below thing to resolve the issue:
set the condition to do not match the pattern:
<conditions>
<add input="{REQUEST_URI}" pattern="\/(.*).img.js" negate="true" />
</conditions>
or set <rule name="img" stopProcessing="true">
<rule name="img" stopProcessing="true">
<match url="\/(.*).img" />
<conditions>
<add input="{REQUEST_URI}" pattern="\/(.*).img.js" negate="true" />
</conditions>
<serverVariables />
<action type="Rewrite" url="/handlers/img.js" logRewrittenUrl="true" />
</rule>
I'm trying to create a redirect rule for a .NET Core project that would replace a query string value so to help deploy a migration on some identifiers. For example the URL:
http://www.somesite.com/page.html?somevar=abc&id=1234&othervar=cde
should redirect to
http://www.somesite.com/page.html?somevar=abc&id=b64540a6-b12d-443f-973f-673e4451ccbe&othervar=cde
On the rewrite file I've created a rewrite map as such:
<rewriteMaps>
<rewriteMap name="newIdentifierMap">
<add key="1234" value="b64540a6-b12d-443f-973f-673e4451ccbe" />
</rewriteMap>
</rewriteMaps>
But now I'm having some trouble creating the rule to use this map. This is what I was doing...
<rule>
<match url=".*" />
<conditions>
<add input="{newIdentifierMap:REQUEST_URI}" pattern="(.*)id=([0-9]+)(.*)" />
</conditions>
<action type="Redirect" url="" RedirectType="Permanent" />
</rule>
Now I'm block without knowing how exactly to replace the values in the map.
Thanks for any help!
Solution
After checking the answer provided by #abraham-qian I was able to solve the issue by applying the following rules:
<rule>
<match url="(.*)" />
<conditions>
<add input="{QUERY_STRING}" pattern="(.*)(\bid=([0-9]+))(.*)" />
</conditions>
<action type="Redirect" url="{R:0}?{C:1}id={newIdentifierMap:{C:3}}{C:4}" RedirectType="Permanent" appendQueryString="false" />
</rule>
<rewriteMaps>
<rewriteMap name="newIdentifierMap">
<add key="1234" value="b64540a6-b12d-443f-973f-673e4451ccbe" />
</rewriteMap>
</rewriteMaps>
This seems to be working fine with any number of variables before or after the id variable in the querystring.
In order to match the ID segment, we could use {Query_String} server variable.
Please refer to below code snippets,
<rewrite>
<rules>
<rule name="MyRules" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{QUERY_STRING}" pattern="(.*)(\bid=([0-9]+))(.*)" />
</conditions>
<!--{C:3} is the value of id, it is referred by the above condition.-->
<action type="Redirect" url="Https://vabqia969vm:448/{MyMap:{C:3}}" appendQueryString="false" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="MyMapName" defaultValue="">
<add key="1234" value="HtmlPage1.html"></add>
</rewriteMap>
</rewriteMaps>
</rewrite>
However, there is an issue that we should uncheck the option Append Query String, or will cause an endless loop since the appended query string meets the condition. We have to match each query field one by one. Like this,
(somevar=.*)&(\bid=([0-9]+))&(othervar=.*)
We had better modify the rules according to your situation.
Feel free to let me know if there is anything I can help with.
First of all, I need to say that after hours googling, I could not find a way to to get the result I need.
Here's the problem:
I have 2 domains for my website, for example: (foo.com) and
(bar.com)
I need foo.com domain to be redirected to HTTPS
I need bar.com to remain on its HTTP and do NOT redirect to HTTPS
I have tried many rules, but none of them did the job. for example:
<rule name="Force HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{REQUEST_URI}" negate="true" pattern="^(www.)?bar.com$$" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
This should redirect foo.com to HTTPS:
<rule name="Add WWW prefix to foo.com and use HTTPS" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^foo\.com" />
</conditions>
<action type="Redirect" url="https://www.foo.com/{R:1}" redirectType="Permanent" />
</rule>
And for bar.com:
<rule name="Force NonHTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="on" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/{REQUEST_URI}" />
</rule>
Take a look at stopProcessing attribute in the first rule. It should stop processing of next rules when the foo.com will be matched. This won't allow "Force NonHTTPS" rule to trigger.
I am trying to rewrite the rule so that if no .svc comes in URL it should rewrite and append .svc in URL.
These are my rules:
<rewrite>
<rules>
<rule name="RemoveSVC" stopProcessing="true">
<match url="localhost/RestApp/Services/([a-zA-Z0-9]*)/(.*)$" />
<action type="Rewrite" url="localhost/RestApp/Services/{R:1}.svc/{R:2}"
appendQueryString="true" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
Can anybody tell me why is this rule not working?
I think you want:
<rewrite>
<rules>
<rule name="RemoveSVC" stopProcessing="true">
<match url="localhost/RestApp/Services/([a-zA-Z0-9]*)/(.*)" />
<action type="Rewrite" url="localhost/RestApp/Services/{R:1}.svc/{R:2}"
appendQueryString="true" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
Remove the $ sign on the end.
I'd also get rid of the localhost/ part because that would only work on your local dev PC, when you deploy into production it won't be localhost any more:
<match url="RestApp/Services/([a-zA-Z0-9]*)/(.*)" />
<action type="Rewrite" url="RestApp/Services/{R:1}.svc/{R:2}"
appendQueryString="true" logRewrittenUrl="true" />