Ignore match in web.config rewrite rule - url-rewriting

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".

Related

url rewrite rule to parse url dynamically

I am using rewrite map method to achive my seo friendly urls.
<rewriteMaps>
<rewriteMap name="Destinations">
<add key="/point-a-to-point-b" value="/destination-final.asp?from=point%20a&to=point%20b" />
</rewriteMap>
</rewriteMaps>
<rules>
<rule name="Rewrite rule1 for Destinations">
<match url=".*" />
<conditions>
<add input="{Destinations:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="{C:1}" appendQueryString="false" />
</rule>
</rules>
My problem is I have too many destinations and having to write a map for each results in 500 error. I believe there is a limit to the number of maps you can have on single web.config file.
would it be possible to achive this using a wildcard rule?
that would parse the url and use the bit before "to" as starting point and the bit after "to" as end point and send it to the file as querystring?
for example
/newyork-to-texas
would send the following querystring:
from=newyork&to=texas
Could you please share a detailed error message for 500 error. if you want to achieve your requirement /newyork-to-texas to from=newyork&to=texas you could use below url rewrite rule:
<rule name="send value to query string" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{REQUEST_URI}" pattern="(.*)/(.*)\-to\-(.*)" />
</conditions>
<action type="Redirect" url="http://localhost:746/default.aspx?from={C:2}&to={C:3}" appendQueryString="false" />
</rule>
Regards,
Jalpa.

Configure correct routing for folder and file with the same naming on IIS

I have site hosted IIS with hidden extentions
using this rule
<rule name="Hide .html ext">
<match ignoreCase="true" url="^(.*)"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
<add input="{REQUEST_FILENAME}.html" matchType="IsFile"/>
</conditions>
<action type="Rewrite" url="{R:0}.html"/>
</rule>
<rule name="Redirecting .html ext" stopProcessing="true">
<match url="^(.*).html"/>
<conditions logicalGrouping="MatchAny">
<add input="{URL}" pattern="(.*).html"/>
</conditions>
<action type="Redirect" url="{R:1}"/>
</rule>
The main problem is that i have file that without extension has same naming that one of my folder
for example
wwwroot/page.html
wwwroot/page/page.html
When this rule applying server return
403 - Forbidden on when i call www.test.com/page
and all works fine when i call www.test.com/page/page
Is it possible to configure url rewrite module to correct work with both of this path?
You can do some workaround for that problem. If you will delete this condition: <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
Then your HTML page will work for this url www.test.com/page and www.test.com/page/page but will not for www.test.com/page/ (it will return forbidden).
If page.html is single exception in your system and you will not have the same collisions, then you can also do in another way, create the additional rule for your url. Just add this rule before Hide .html ext rule:
<rule name="Exception for page" stopProcessing="true">
<match url="^(page)(\/?)$" />
<action type="Rewrite" url="{R:1}.html" />
</rule>
In this case, all URLs will work correctly:
www.test.com/page
www.test.com/page/
www.test.com/page/page

IISRewrite encoding of %2f in path

So I have a path like this (I am using webforms):
folder/first/second/
which has the following rewrite rule behind it
<rule name="firstLevel">
<match url="^folder/([^/]+)/([^/]+)/?$" />
<action type="Rewrite" url="firstSecond.aspx?param1={R:1}&param2={UrlEncode:{R:2}}" />
</rule>
my issue is when I try and pass the following:
folder/first/sec%2fond/ (I want R2 to be sec%2fond where I will urlDecode it back to the page. for a result like "sec/ond".
However my rule keeps taking it as though I want
folder/first/sec/ond
Requested URL
http://localhost:85/research/first/sec/ond/
Physical Path
\rewritetest\folder\first\sec\ond\
Thanks for any assists..
I found a working solution to this issue for anyone else.
<rule name="secondLevel">
<match url="^folder/(.+)/(.+)/?$" ignoreCase="true" />
<action type="Rewrite" url="firstsecond.aspx?param1={C:1}&param2={C:2}" />
<conditions>
<add input="{UNENCODED_URL}" pattern="/folder/([^/]+)/([^/]+)/?$" />
</conditions>
</rule>

Directory Specific url rewriting in IIS ColdFusion

I have site
http://example.com/school/student.cfm?id=100
Also, i have another link http://example.com/collage/student.cfm?id=200
I want to write a URL rewrite rule which always re-write the http://example.com/school/student.cfm?id=100
to http://example.com/school/student/100
and
http://example.com/collage/student.cfm?id=200
to http://example.com/collage/student/200
I have written rule like this but that will always use 1 directory, But I want this to be working for all directories.
<rule name="Redirect to school with ONE parameter" 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="school/student.cfm?id_Name={R:1}" />
</rule>
There are many ways to solve this. The range of solution goes from - only rewriting school and collage - to rewriting any path that ends with student - to using a generic pattern that rewrites everything.
To give you an idea how to do that with IIS' regexp:
<match url="^(collage|school)/student/([0-9]+)/?$" />
<action type="Rewrite" url="{R:1}/student.cfm?id={R:2}" />
<match url="^([^/]+)/student/([0-9]+)/?$" />
<action type="Rewrite" url="{R:1}/student.cfm?id={R:2}" />
<match url="^([^/]+)/([^/]+)/([0-9]+)/?$" />
<action type="Rewrite" url="{R:1}/{R:2}.cfm?id={R:3}" />

IIS8 rewrite to force https except for a certain path

My site is asp.net.
I have a wordpress blog in the blog folder and everything works great.
My main web.config has a working rule that forces https on everything.
I have successfully added a rule in the web.config in the blog folder not to redirect to https.
My problem is that I want to exclude the wp-content/uploads/* folder from that rule.
i.e. I want the images in the upload folder to be allowed to load on https too.
(My reason is that I refer to them in my main site and the way it is, I get security messages that I have insecure content on my https pages)
My code is:
<rule name="Remove https" enabled="true" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_URI}" pattern="^wp-content/uploads/.*" negate="true" />
<add input="{HTTPS}" pattern="on" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/blog/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
What am I doing wrong?
Thanks
Your code in problem dear plz try below code can this help you.
Something Wrong in your pattern of "^wp-content/uploads/.*" you try below code can this help you.
<rule name="Remove https" enabled="true" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_URI}" pattern="^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*)" negate="true" />
<add input="{HTTPS}" pattern="on" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/blog/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>

Resources