IIS 7 rewrite for subfolders - iis

I am trying to setup some rewrite rules for sub folders.
Example
Redirect the following
/somefolder
/somefolder/
to
/somefolder/default.aspx
<rewrite>
<rules>
<rule name="Some Folder">
<match url="^/somefolder$" />
<action type="Rewrite" url="/Somefolder/default.aspx" />
</rule>
</rules>
</rewrite>

Related

IIS Rewrite part of url to url-Parameter

How can I rewrite the URL:
test.xy/Objekte/Haus-in-Rheinstetten
to
test.xy/Objekte/Haus-in.cfm?Ort=Rheinstetten
The part behind the second - in Haus-in-Rheinstetten convert to a url-Parameter
You can use web.config file.
This file located in the folder of your site.
Example of rewriting rule:
<rewrite>
<rules>
<rule name="Rewrite to some page">
<match url="http://some.site/some.page" />
<action type="Redirect" url="http://other.site/other.page" />
</rule>
</rules>
</rewrite>

Redirect any Sub folder to root

Here is the situation:
I need to redirect www.mydomain.com/anything/test.txt to www.mydomain.com/test.txt.
Here is what i have tried so far:
<rewrite>
<rules>
<rule name="Rule1" stopProcessing="true">
<match url="^.*/test.txt" />
<action type="Rewrite" url="{R:1}/{R:3}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
Your help will be greatly appreciated.

IIS Rewrite - Remove real folder from the URL

Please, I have this folder:
root/teste_seo/script.asp
Instead to use the url:
www.mysite.com/teste_seo/script.asp
I need this url using IIS rewrite:
www.mysite.com/script.asp
I try to use the rule from this link but didn't work:
IIS 7.5 URL Rewrite - Rewrite a Folder from an URL
Please, how can I write this rule?
PS.: For any *.asp file inside teste_seo folder.
The following rule should do the trick:
<rule name="teste_seo" stopProcessing="true">
<match url="^script.asp" />
<action type="Rewrite" url="/teste_seo/script.asp" />
</rule>
Then just link to the www.mysite.com/script.asp
Edited after comment from OP:
If so you can use the following rule as long as you have a copy of the script files in the root of your document:
<rule name="teste_seo" stopProcessing="true">
<match url="^teste_seo/([^\.]+\.asp)" />
<action type="Redirect" url="/{R:1}" />
</rule>
And if you need all script files to point to the same one you can use:
<rule name="teste_seo" stopProcessing="true">
<match url="^teste_seo/([^\.]+\.asp)" />
<action type="Redirect" url="/script.asp" />
</rule>
Edited again after clarification:
These 2 rules should then be the fix you need:
<rule name="teste_seo_redirect" stopProcessing="true">
<match url="^teste_seo/([^\.]+\.asp)" />
<action type="Redirect" url="/{R:1}" />
</rule>
<rule name="teste_seo_rewrite" stopProcessing="true">
<match url="^([^\.]+\.asp)" />
<action type="Rewrite" url="/teste_seo/{R:1}" />
</rule>

URL rewrite and redirect between hosts

I have the following rewrite rule to redirect any conetnt from a host, hostA.com to the home page of a new host, hostB.com. I also want to browser url to change to www.HostB.com
<rewrite>
<rules>
<rule name="301 redirect entire site" stopProcessing="true">
<match url="^hostA(.*)$" />
<action type="Redirect" redirectType="Permanent" url="http://www.hostB.com" appendQueryString="true" />
</rule>
</rules>
</rewrite>
But that does not work. How can I fix this please.
you can doit like this
<rule name="domain redirect" enabled="true" stopProcessing="true">
<match url="^hostA(.*)$" />
<action type="Redirect" url="http://hostb.example.com/{R:0}" appendQueryString="true" />
</rule>

How to append query string & value via IIS rewrite rule?

I'm running IIS 7 with the offical rewrite rule module installed. I'd like to create a rewrite rule to match this URL:
http://www.sample.com/en-us/test.aspx?q=keyword
After rewriting the expected result would be:
http://www.sample.com/en-us/test.aspx?q=keyword&flag=value
How can I create a rule to implement this?
I've tested the following rule, but no luck, it always got redirect loop error:
<rewrite>
<rules>
<rule name="test" stopProcessing="true">
<match url="(.*)/test\.aspx(.(?!flag=value))*$" />
<action type="Redirect" url="{R:0}&flag=value" appendQueryString="false" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
Found the solution by myself, just share it.
<rewrite>
<rules>
<rule name="Redirect for download result page" stopProcessing="true">
<match url="(.*)/test.aspx(.*)" />
<action type="Redirect" url="{R:1}/test.aspx?rf=sp" appendQueryString="true" redirectType="Found" />
<conditions>
<add input="{QUERY_STRING}" pattern="flag=value" negate="true" />
</conditions>
</rule>
</rules>
</rewrite>

Resources