I have a directory at etreecycle.co.uk/austincollins/.
I want to point the subdomain austin.etreecycle.co.uk to /austincollins/.
Inside /austincollins/ there is a folder called /test/.
So to get to /austincollins/test/ the url should be austin.etreecycle.co.uk/test/.
But the url shows as austin.etreecycle.co.uk/austincollins/test/.
Here is the Rewrite rule:
<rule name="austin.etreecycle.co.uk" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^austin.etreecycle.co.uk$" />
<add input="{PATH_INFO}" pattern="^/austincollins/" negate="true" />
</conditions>
<action type="Rewrite" url="\austincollins\{R:0}" />
</rule>
How can I remove the /austincollins/ from the URL, and why is is showing?
Also:
When you go to austin.etreecycle.co.uk it shows the index file in /austincollins/. This is why I don't understand why you have to go to austin.etreecycle.co.uk/austincollins/dev/ and not just /dev/.
Related
I have a working rule that removes www. for all urls coming in. I have a webserivce that the redirect will change from a POST to a GET. I need to exclude the URL https://www.foo.net/WebServices/service.asmx from this rule.
I have looked at other solutions on SO with no success.
<rewrite>
<rules>
<rule name="Remove WWW" enabled="true" stopProcessing="true">
<match url=".*"/>
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)(foo\.net)" />
</conditions>
<action type="Redirect" url="https://{C:2}/{R:1}" />
</rule>
</rules>
</rewrite>
You can do that easily by adding a condition to "not match" (aka adding "negate='true'" ), something like this should work:
<rules>
<rule name="Remove WWW" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.foo\.net$" />
<add input="{URL}" pattern="^/WebServices/service\.asmx$" negate="true" />
</conditions>
<action type="Redirect" url="https://foo.net/{R:1}" />
</rule>
</rules>
I cannot create rule for redirecting users on my ws-federation driven site when using improper browser: causes infinite loop... "Chrome" is now taken for simplicity, actually I will be testing against IE less than 9.
<rule name="UserAgentCheck" stopProcessing="true">
<match url=".*" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_URI}" pattern="BrowserIsNotSupported" negate="true" />
<add input="{QUERY_STRING}" pattern="BrowserIsNotSupported" negate="true" />
<add input="{HTTP_USER_AGENT}" pattern="Chrome" />
</conditions>
<action type="Redirect" url="Isolate/BrowserIsNotSupported" appendQueryString="false" redirectType="Permanent" />
</rule>
I sequentially receive:
301, 302, 307, 200 responses and everything starts over...
I even cannot figure out, if it's a logic error (match all against several conditions) or problem, related to using ws-federation. But anyway, I see BrowserIsNotSupported page, present as a part of wctx parameter and have no idea why it's not taken into consideration by QUERY_STRING condition.
http://localhost:14961/wsFederationSTS/Issue/?wa=wsignin1.0&wtrealm=http%3a%2f%2flocalhost%3a50207%2f&wctx=rm%3d0%26id%3dpassive%26ru%3d%252fIsolate%252fBrowserIsNotSupported&wct=2014-11-12T11%3a41%3a05Z
Little changes.
1) I have removed "AllowAnonymous" attribute from BrowserIsNotSupported method: let he be authenticated and then shown the page with message (no menu, no anything - just message and link to authentication portal)
2) Requests to the site which do matter are those that contain FedAuth cookie.
So modified solution for my problem is as follows:
<rule name="UserAgentCheck" stopProcessing="true">
<match url=".*" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_URI}" pattern="BrowserIsNotSupported" negate="true" />
<add input="{QUERY_STRING}" pattern="BrowserIsNotSupported" negate="true" />
<add input="{HTTP_COOKIE}" pattern="FedAuth" />
<add input="{HTTP_USER_AGENT}" pattern="MSIE 8.0|MSIE 7.0b|MSIE 7.0|MSIE 6.0b|MSIE 6.0|MSIE 5.5b1|MSIE 5.5|MSIE 5.0|MSIE 5.01|MSIE 4.0" />
</conditions>
<action type="Redirect" url="Isolate/BrowserIsNotSupported" appendQueryString="false" redirectType="Found" />
</rule>
I already have the following code in my web.config which does pretty much what I want.
<rewrite>
<rules>
<rule name="Canonical Host Name" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^www.mysite.com$" negate="true" />
</conditions>
<action type="Redirect" url="{MapSSL:{HTTPS}}www.mysite.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="MapSSL" defaultValue="OFF">
<add key="ON" value="https://" />
<add key="OFF" value="http://" />
</rewriteMap>
</rewriteMaps>
</rewrite>
There is just one element missing from what I can see. The query element of the url will remain as is - mixed/upper case - how can I ensure all of the url is lowercase?
You can add a lowercase rule.
<rule name="LowerCaseRule" patternSyntax="ExactMatch" stopProcessing="true">
<matchurl="[A-Z]" ignoreCase="false"/>
<actiontype="Redirect" url="{ToLower:{URL}}"/>
</rule>
its part of default template, Under Search Engine Optimization (SEO) template, select Enforce lowercase URLs
I have the following web.config URL Rewrite rule:
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^propertysearch\.asp$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^urlrewrite=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="propertysearch.asp?urlrewrite={R:1}" />
</rule>
The problem is it is applying this to everything so what I want to do is change the match url syntax to tell it to ONLY run when "-to-rent-in-" is included in the URL, so...
www.domain.com/villas-to-rent-in-florida
WILL qualify and have the rule applied, BUT this wouldn't
www.domain.com/testentry
I have tried different variants but it keeps hitting an error :(
To get the url to trigger the rewrite only when -to-rent-in- is part of the first portion of the url, you could use:
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^(.+-to-rent-in-.+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="propertysearch.asp?urlrewrite={R:1}" />
</rule>
url="^(.+-to-rent-in-.+)/?$" will match any url containing at least one character before -to-rent-in- and at least one after.
You don't want to limit the character(s) before or after to be only alphanumeric since your url can be like: www.domain.com/apartments-to-rent-in-new-york (where new-york contains a -)
i want to check that file with requestedurl + .php is exists or not.
in apache i can do this with RewriteCond %{REQUEST_FILENAME}.php -f
so that it can rewrite my request test.com/login to test.com/login.php
i want to do same with iis rewrite rule.
i have tried with following.
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}\.php" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="{R:1}.php" />
</rule>
<rule name="Imported Rule 2">
<match url="^(.*)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="allpages.php" />
</rule>
</rules>
</rewrite>
but it doesnt works.
thanks in advance for help
Change {REQUEST_FILENAME}\.php to {REQUEST_FILENAME}.php in first rule.
Further there is no need to check if requested URL exists as directory.
To rewrite 'test.com/login' to 'test.com/login.php' only if login.php exits, use:
<rule name="Rewrite to PHP">
<match url="^(.*)$" />
<conditions>
<add input="{REQUEST_FILENAME}.php" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="{R:0}.php" />
</rule>
Tested