IIS-10 configuration for url rewrite on windows server-2016 - url

I have url abc.com/process/login, so how to check is this "process" word present after.com/ using regular expression url pattern?
I do have scenarios abc.com/image/think/process/depth, abc.com/image/think/process_image/depth, abc.com/process_url/machine/code. Then it shouldn't rewrite as "process" word not present next to .com/
So rewrite the url only if "process" word present next to .com/
example: abc.com/process/login , abc.com/process/signup etc..

Try to use this matching rule:
<rewrite>
<rules>
<rule name="Test">
<match url="abc.com/process/(.*)" />
<action type="Rewrite" url="URL address you rewrite" />
</rule>
</rules>
</rewrite>

Related

URL Rewrite match question mark

I am trying to match a ? in my url rewrite section in my web config, I am using IIS Express so I can not add the rule via IIS manager.
<rules>
<rule name="LocationDetail" stopProcessing="true">
<match url="^location-detail\?province=([A-Za-z]{2})$" />
<action type="Redirect" url="LocationDetail"/>
</rule>
</rules>
As you can see I am already escaping the ?. Is there something I am missing?
I also modify the url so that the the question mark is not needed to see if the question mark is the reason it was not matching.
<rules>
<rule name="LocationDetail" stopProcessing="true">
<match url="^location-detailprovince=([A-Za-z]{2})$" />
<action type="Redirect" url="LocationDetail"/>
</rule>
</rules>
It was. Once the question mark was removed it matched correctly and I was redirected correctly.

IIS URL Rewrite multiple parameters

I am really confused about the URL rewrite interface. I dont understand what i need to do.
I have an url as:
www.example.com/diretory/subdirectory/index.html?param1=1&param2=2&param3=2&param4=7
I want to hide this url in a <a>-href tag, which displays "Example Tag".
When the url is requested it should rewrite it to
www.example.com/program/location/year/vacancie
I allready tried this:
<system.webServer>
<rewrite>
<rules>
<rule name="ProgramRewrite" patternSyntax="ECMAScript" stopProcessing="true">
<match url="\?([^/]+)&([^/]+)&([^/]+)&([^/]+)" />
<action type="Rewrite" url="www.example.com/program/location/year/vacancie" logRewrittenUrl="true" />
<conditions>
</conditions>
</rule>
</rules>
</rewrite>
</system.webServer>
In the URL Rewrite Interface the Test Pattern said it is working and gets:
?param1=1&param2=2&param3=2&param4=7
param1=1
param2=2
param3=2
param4=7
I checked the log url rewrite as well, but in my logs it is not shown.
2017-03-20 16:29:24 192.168.253.146 GET /diretory/subdirectory/index.html param1=1&param2=2&param3=2&param4=7 88 - 192.168.253.146 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/56.0.2924.87+Safari/537.36 - 304 0 0 4
ps: the urls are not working and only for illustrative purpose.
The match URL only matches the URL and does not take the querystring into account. You will need to add a condition for this. Also do you want to rewrite this (so the server internally executes the new URL) or redirect (so the server will request the browser to go to the new URL and URL changes in address bar). In case you want to rewrite you should not add the domain again, in case you want to redirect add http:// as well. Assuming a rewrite is what you want use below rule:
<rule name="ProgramRewrite" patternSyntax="ECMAScript" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="/program/location/year/vacancie" logRewrittenUrl="true" />
<conditions>
<add input="{QUERY_STRING}" pattern="([^/]+)&([^/]+)&([^/]+)&([^/]+)" />
</conditions>
</rule>

IIS Url redirect match pattern

I am redirecting URL in the config file. This is what I am doing:
<rule name="award temp redirect" stopProcessing="true">
<match url="(.*?)/?award.aspx$" />
<action type="Redirect" url="http://www.abc.com.au/award.aspx" redirectType="Temporary" />
</rule>
This is working fine for /award.aspx but I want to add for /awards or /award as well. Currently I have create separate rules for /awards or /award.
Can I add these two into one match. If the Url is /award.aspx or /award or /awards then redirect to http://www.abc.com.au/award.aspx.
match accept regex for url value. Try:
<match url="(.*?)/?awards?(\.aspx)?$" />
This will match award, award.aspx, awards and awards.aspx.
Update to match /test as well:
<match url="(.*?)/?(awards?|test)(\.aspx)?$" />
It is just a regular expression. You can match whatever you want.

How can i remove "Sections" from url by url writing?

I am working on vb.net application and i need to remove word "sections" from the url.
url: http://www.examplewebsite.com/sections/page.aspx
This is what i need to do by regular expression in web.config.
You can use the following rewrite rule in your web.config file:
<rewrite>
<rules>
<rule name="Hide sections">
<match url="^(.+)$
<action type="Rewrite" url="sections/{R:1}" />
</rule>
</rules>
</rewrite>

IIS rewrite virtual folder

I need to create a URL rewrite rule in IIS for the following:
From:
http://hostname/virtual_path_folder/myisapi.dll?a=1&b=1
To:
http://hostname/myisapi.dll?a=1&b=1
Basically, I'd just like to hide the virtual_path folder if possible.
You could go with the 2 following rules:
<rules>
<rule name="Redirect if virtual_path_folder" stopProcessing="true">
<match url="^virtual_path_folder/(.*)$" />
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="Rewrite to sub folder">
<match url="^.*$" />
<action type="Rewrite" url="virtual_path_folder/{R:0}" />
</rule>
</rules>
The first one, Redirect if virtual_path_folder, will redirect every request starting with virtual_path_folder/. It will prevent anyone from accessing your content using the sub folder.
The second one rewrites any request (^.*$) to the sub folder: virtual_path_folder/{R:0}

Resources