I have a IIS server running sites using 2 domains with multiple sites on each.
I'm trying to write a url rewrite rule that only affects the one site
The domains is this
*.it.test.com
*.test.com
I have tried this rule but it seems to it do not seem to work - maybe I need a wildcard or something in the domian.
I'm trying to hit the subdomains of it.test.com
<rule name="Redirect to HTTPS" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" ignoreCase="true" negate="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" ignoreCase="true" matchType="Pattern" pattern="^it.test.com$" />
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" redirectType="Temporary" />
</rule>
A couple of sites names could be this
bb.it.test.com
aa.it.test.com
cc.test.com
As far as I know, if you choose patternSyntax="Wildcard", the {HTTP_HOST} in conditions is also use wildcard to match.
So this is reason why pattern="^it.test.com$" match failed. Wildcard is a special sentence, mainly including (*) and (?). Start with (^) and end with ($) is the usage of regular expressions.
Match fail:
Even you change patternSyntax="regular expressions", it will still fail because of ^. bb.it.test.com is not start with it but bb.
Two solutions.
Use regular expressions and set the pattern="(.*).it.test.com$", but it only match bb.it.test.com aa.it.test.com. pattern="(.*).test.com$" will match both of them.
Still use Wildcard but set the pattern="*.test.com".
Related
here is my rule:
<rule name="RedirectHttps04" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_URI}" pattern="^some-url-here$" />
<add input="{HTTPS}" pattern="^off$" />
</conditions>
<action type="Redirect" url="https://www.example.com/some-url-here" />
</rule>
With the above rule I would like to redirect a specific URL to https and keep all the other ones as they are.
So when user goes to:
www.example.com/some-url-here
http://example.com/some-url-here
http://www.example.com/some-url-here
I would like them to be redirected to:
https://www.example.com/some-url-here
But, after going through many versions and options available here - non of them worked, after reading multiple articles I don't see why the rule above doesn't work (doesn't redirect).
I'm using IIS 8.5.96
More info:
{HTTPS} parameter appears to be always "off"
{HTTP} is either "" for http or "off" for https, but even so the rule doesn't work
I have set to redirect to test.html?p={CACHE_URL} and both appears to take me to test.html?p=http://example.com
The only thing I have that works is a rule which appends parameter at the end if it's not appended, a very ugly hack but ensures user ends up on https :/
I'm looking to set up a rewrite rule in my web.config file which forces URLs to use the 'www' sub-domain. This is done like so:
<rules>
<rule name="Add WWW" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www\.)(.*)$" />
</conditions>
<action type="Redirect" url="http://www.{C:0}{PATH_INFO}" redirectType="Permanent" />
</rule>
However, the project is running multiple websites on multiple domains, some of which use SSL and some don't.
The code above hard-codes http:// into the redirect. What I'm looking to do is to abstract this such that the http or https protocols are maintained during the redirect without being hard-coded.
Some examples of the desired results are:
http://olddomain.com > http://www.newdomain.com
https://someolddomain.com > https://www.somenewdomain.com
Many thanks.
I found a reference which explains one approach in doing this. It uses rewrite key/value pairs as a 'variable' in the action url, as (as far as I can find out) there's no way currently to grab the protocol as a native variable inside the rule.
The rule has been modified as follows, which should do what's required:
<rewrite>
<rules>
<rule name="Add www maintain https" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www\.)(.*)$" />
</conditions>
<action type="Redirect" url="{MapSSL:{HTTPS}}www.{C:0}{PATH_INFO}" redirectType="Permanent" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="MapSSL" defaultValue="http://">
<add key="ON" value="https://" />
<add key="OFF" value="http://" />
</rewriteMap>
</rewriteMaps>
</rewrite>
There's also another reference which includes this amongst alternative ways to achieve the same thing.
Looking to create a working IIS rewrite (not a redirect) rule to rewrite http{s}://www.client1.com/page1.htm to https://client1.mysite.com/myapp/client1/page1.htm - I just can't get it working. Driving me a little mad.
My main problem is getting the domain name WITHOUT the TLD part returned as an R{x} or C{x} parameter...
Note the client name is in two places in the target url - AND Note that the original url could be client2.com or client3.org or client4.net
This rule will rewrite it for you:
<rules>
<rule name="Rewrite clients domains" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)?([a-zA-Z0-9\-\.]+)\.(\w+)$" />
</conditions>
<action type="Rewrite" url="{MapProtocol:{HTTPS}}://{C:2}.mysite.com/myapp/{C:2}/{R:0}" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="MapProtocol">
<add key="on" value="https" />
<add key="off" value="http" />
</rewriteMap>
</rewriteMaps>
I have and issue where a rule in the web.config is catching something I want it to ignore.
I have:
http://domain.com/video-conferencing-room/australia/australian-capital-territory/barton
Getting picked up by the below rule. I've added part hoping that would fix it, but no joy. The routing for that
<rule name="video-conferencing-room-country">
<match url="^video\-conferencing\-room/([0-9a-z- ]+)" />
<conditions>
<add input="{HTTP_HOST}" matchType="Pattern" pattern="^video\-conferencing\-room/([0-9a-z- ]+)/([0-9a-z-, ]+)/([0-9a-z-, ]+)" ignoreCase="true" />
</conditions>
<action type="Redirect" url="/meeting-rooms/{UrlEncode:{R:1}}" redirectType="Permanent" />
</rule>
but this condition is stopping urls like this:
http://domain.com/video-conferencing-room/australia
from hitting the rule.
I updated to use {URL}, and :
http://domain.com/video-conferencing-room/australia
now works,
but I still have an issue that
http://domain.com/video-conferencing-room/australia/australian-capital-territory/barton
Is getting rewritten by this rule:
<rule name="video-conferencing-room country state">
<match url="^video\-conferencing\-room/([0-9a-z- ]+)/([0-9a-z-, ]+)" />
<conditions>
<add input="{URL}" matchType="Pattern" pattern="^video\-conferencing\-room/([0-9a-z- ]+)/([0-9a-z-, ]+)/([0-9a-z-, ]+)" ignoreCase="true" negate="true" />
</conditions>
<action type="Redirect" url="/meeting-rooms/{UrlEncode:{R:1}}/{UrlEncode:{R:2}}" redirectType="Permanent" />
</rule>
When I would like it ignored.
Do you know what I'm doing wrong?
Your condition is not correct, you are setting it with {HTTP_HOST} which is only the host name part, namely in your example domain.com.
Instead try using the {URL} as the input which will include the URL including the video-conferencing... parts.
Try adding $ at the end
^video\-conferencing\-room/([0-9a-z- ]+)/([0-9a-z-, ]+)$
and you can remove the condition. $ signifies "end of string".
Is there a way in IIS to redirect the following request:
http://mysite/report1/img/logo.png to http://mysite/myapplication/report1/images/logo.png for ALL images in the img directory without having to explicitly map them individually?
Additional requirement- I have THOUSANDS of reports on a drive mapped to the 'report1' virtual directory- each with their own 'img' directory- so there is no reasonable way to use IIS manager to map those directories individually either.
I'm looking to see if there is some way to add a wildcard (or other) HttpRedirect in the IIS server web.config file to correctly map all the images for all the reports. I tried:
<add wildcard="*res/img/" destination="/reporter/content/images/reportimages" />
But that seemed to have no effect.
EDIT: Some more research shows that using the URL Rewrite module might work... but so far I haven't gotten it to work.
My rule looks like this (in web.config):
<rules>
<rule name="Redirect rule1 for ImageRedirect">
<match url=".*" />
<conditions>
<add input="{ImageRedirect:{REQUEST_URI}}" matchType="Pattern" pattern="/res/img/(.+)" ignoreCase="true" negate="false" />
</conditions>
<action type="Redirect" url="{HTTP_HOST}/reporter/content/reporterimages/{C:1}" appendQueryString="false" />
</rule>
</rules>
You were on the right track using the URL Rewrite module.
The most simple rule in your case would be:
<rule name="Rewrite images" stopProcessing="true">
<match url="^/report1/img/(.+)$" />
<action type="Rewrite" url="/myapplication/report1/images/{R:1}" />
</rule>
It does check if the requested url matches ^/report1/img/(.+)$ and if yes, trigger a rewrite to your new folder.
If you want to use a Redirect instead:
<rule name="Redirect images" stopProcessing="true">
<match url="^/report1/img/(.+)$" />
<action type="Redirect" url="/myapplication/report1/images/{R:1}" />
</rule>
(If you don't specify it, by default a Redirect is permanent (301))