can anyone tell me whats wrong with this IIS URL rewrite? - iis

So i should be able to visit rsstest/test.xml and be forwarded to article.xml if i don't have a user agent of wibble.
why doesn't this work?
<rule name="df" patternSyntax="ExactMatch" stopProcessing="true">
<match url="^rsstest/test.xml" negate="true" />
<conditions>
<add input="{HTTP_USER_AGENT}" pattern="Wibble" negate="true" />
</conditions>
<action type="Rewrite" url="article.xml" />
</rule>
thanks in advance

Try changing the rule to this.
<rule name="df" patternSyntax="ExactMatch" stopProcessing="true">
<match url="^rsstest/test.xml" negate="true" />
<conditions>
<add input="{HTTP_USER_AGENT}" pattern="Wibble" negate="true" />
</conditions>
<action type="Redirect" url="article.xml" />
</rule>
Using redirect sends a HTTP 301 or 302 to the client, telling the client that it should try to access the page using another URL.
Rewriting happens on the server, and simply is a translation of one URL to another, that is used by your web application. The client will not see any change.

Related

IIS UrlRewrite for subdomain to subdirectory

I'm trying to simply do a subdomain rewrite to a directory. Example, http*://member.mydomain.com would redirect to http*://mydomain.com/memberarea/. I don't want ALL subdomains to do this, just the defined "member" one.
Here is the code I have, and it does not work. I'm obviously missing something...
<rule name="Member Pages" stopProcessing="true">
<match url="^(.+)" />
<conditions>
<add input="{HTTP_HOST}" pattern="(.*)://member\.example\.com($)" />
</conditions>
<action type="Redirect" url="{C:1}://example.com/MemberArea/{R:1}" />
</rule>
My hope is this would also make http://member.example.com/Report/SomeReport.aspx resolve to http://example.com/MemberArea/Report/SomeReport.aspx.
Any help would be greatly appreciated.
You can try this rule will be redirected to the http*://member.mydomain.com http*://mydomain.com/memberarea/
<rule name="test2" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^member\.(.*)$" />
</conditions>
<action type="Redirect" url="http://{C:1}/memberarea" />
</rule>

Exclude Development URL from IIS rewriting rule

I have a IIS URL - re-writing rule that makes sure all the urls have www. -
<rule name="Add www" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="www.example.com" negate="true" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:1}" />
</rule>
This works in production the way I want it to.
However I have a local version of my website set up on my development machine that looks like http://mydomain.local
When I run my local version of the website and go to mydomain.local I get redirected to www.example.com
How can I make the rule ignore my local development URL?
You can try to add a condition to ignore the local development URL.
<rule name="Add www" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="www.example.com" negate="true" />
<add input="{HTTP_HOST}" pattern="http://mydomain.local" negate="true" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:1}" />
</rule>
Best regards,
Sam

URL Rewrite causing redirected you too many times

I am using IIS url rewrite rule to redirect from an IP Address to a domain name with the following rule.
<rule name="IPHit" enabled="true" stopProcessing="false">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="10.32.1.132" />
</conditions>
<action type="Redirect" url="https://daart-qa.sandbox.aimsplatform.com/eds-daas/{R:1}" redirectType="Permanent" appendQueryString="true" />
</rule>
Unfortunately, this results in an infinite loop redirect when I go to https://daart-qa.sandbox.aimsplatform.com/eds-daas.
How can I redirect from the IP address without having an infinite loop on dns entry?
Your rule will redirect 10.32.1.132/eds-daas to https://daart-qa.sandbox.aimsplatform.com/eds-daas/eds-daas. Is that expected behavior?
May I know your only face this infinite loop when you access specific URL or all requests hitted by IP address. What loop URL did you see in web browser developer tool?
Post the symtptom of loop URL would help us find the root cause.
Or you need to redirect request 10.32.1.132/eds-daas to https://daart-qa.sandbox.aimsplatform.com/eds-daas? If so you may need two rules side by side.
<rule name="IPHit" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="10.32.1.132" />
<add input="{REQUEST_URI}" pattern="^/eds-daas(.*)" negate="true" />
</conditions>
<action type="Redirect" url="https://daart-qa.sandbox.aimsplatform.com/eds-daas/{R:1}" redirectType="Permanent" appendQueryString="true" />
</rule>
<rule name="IP-HIT2" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="10.32.1.132" />
<add input="{REQUEST_URI}" pattern="^/eds-daas(.*)" />
</conditions>
<action type="Redirect" url="https://daart-qa.sandbox.aimsplatform.com/eds-daas{C:1}" />
</rule>

How to set a condition in IIS UrlRewrite to check if the URL is valid

I have an issue with setting an condition for my IIS URLRewrite to set it so when the entered url is not valid then it takes you to a set url. for instance you type url: example.local/current_work that would be a valid url so it shows the page however for url : example.local/this_doesnt_exist it will redirect you back to the example.local/current_work etc...
Hope I am clear on this one.
<rewrite>
<rules>
<rule name="Test" stopProcessing="true">
<match url="^scottishtrunkroadsse.amey.local/([_0-9a-z-]+)" negate="false"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="current-works/" />
</rule>
</rules>
<rewrite>
Thank you for any help.
I am using an Umbraco website but I don't think that change anything as the IIS url should be working in the same way.
Thank you in advance.
This rule will redirect example.local/this_doesnt_exist to example.local/current_work:
<rule name="Test" stopProcessing="true">
<match url="^this_doesnt_exist$" />
<action type="Redirect" url="/current_work" />
</rule>

IIS - Forcing the LoginPage over https causes prompt in IE

We are using URL Rewrite module to force the login sectoin of our website over https while keeping all the other section on http. These are the two rules that we have added
<rule name="Others Force HTTP" enabled="true" stopProcessing="true">
<match url="(((.*)/LogOn)|((.*)/Content(.*))|((.*)/Images(.*))|((.*)/Scripts(.*)))" negate="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^ON$" />
</conditions>
<action type="Redirect" url="http://{SERVER_NAME}{REQUEST_URI}" redirectType="Permanent" />
</rule>
<rule name="Force on SSL" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{REQUEST_URI}" pattern="^/users/account/LogOn(\?.*)*$" />
</conditions>
<action type="Redirect" url="https://{SERVER_NAME}{PATH_INFO}" redirectType="Permanent" />
</rule>
However with these rules Internet Explorer shows the prompt that some of the content was not delivered over secured connection whereas Google chrome does not fetch any of the stylesheet, images etc.
Fiddler shows that the web server is redirecting all requests to /Content /Images etc. over HTTP which the IIS server shouldn't do as per the first rule.
We are at our wits ends trying to resolve this problem. Some help would be greatly appreciated.
Nikhil,
Ignoring the HTTPS to http redirection rule "Others Force HTTP" for images and stylesheets would solve this, you can rewrite your condition like this
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^ON$" />
<add input="{REQUEST_URI}" pattern="^/Content*" negate="true" />
</conditions>
Note: You can remove the url matching condition for the contents folder
Hope this helps.

Resources