IIS Rewrite everything after the domain - iis

I have to domains - a.com and b.com. I want to use iis rewrite so that anything going to www.a.com/ will be redirected to www.b.com/index.asp?i=.
For example www.a.com/XXX will be redirected to www.b.com/index.asp?i=XXX
I put (.*?) in the pattern. The problem is when I enter http://www.b.com/index.asp?i={REQUEST_URI} as a redirect action, the redirect url includes a slash. For example www.a.com/XXX is redirected to www.b.com/index,asp?i=/XXX instead of to i=XXX. Is there any way to get rid of the slash?

You could use below url rewrite rule:
<rule name="test1" enabled="true" stopProcessing="true">
<match url=".+" />
<conditions>
</conditions>
<action type="Redirect" url="http://www.b.com/index.asp?i={R:0}" />
Regards,
Jalpa

Related

How can i include a page in an IIS url rewrite rule (redirect)

I'm fairly new to url rewrite and trying to figure this thing out.
I have a website with the following structure:
http://localhost/virtualdirectory1/somepage.aspx?parameter1=x
http://localhost/virtualdirectory2/
Now I added a rule for a redirect (inbound rule):
matches pattern (regex) ^$ to make sure that if anybody goes to http://localhost that they are redirected to http://localhost/virtualdirectory1/somepage.aspx?parameter1=x
This also works fine for http://localhost/?paramter1=x which gets redirected properly.
This still allows me to approach http://localhost/virtualdirectory2/ directly.
However if the user goes to http://localhost/somepage.aspx?paramter1=x they are not redirected to the virtualdirectory1
Could give me some tips on how that can be done?
Thanks!
Is this rule achieve your requirement? It will redirect both http://localhost and http://localhost/somepage.aspx?paramter1=x but it won't redirect http://localhost/.
<rule name="redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{URL}" pattern="^(/somepage\.aspx)?$" />
</conditions>
<action type="Redirect" url="virtualdirectory1/somepage.aspx?parameter1=x" appendQueryString="false" redirectType="Temporary" />
</rule>

IIS URL Rewrite with a pound/number sign "#"

I have a need to rewrite a url for an invoice that has a "#" in the querystring. Evidently the "#" is causing IIS to balk somehow. The rule I have currently is:
^invoice/([_0-9a-z-#]+)
and the action is:
invoice.aspx?id={R:1}
Pretty simple and works fine so long as there's no "#" in the invoice number. Is there any way to include this so it works?
Hash Tags in the URL serve a special purpose to the client browser, not to the server.so Browser did not anything after the '#' character.
To resolve this issue you can try this below url rewrite rule:
<rule name="test # in query string" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{REQUEST_URI}" pattern="invoice/(.+)" />
</conditions>
<action type="Redirect" url="invoice.html?id={UrlEncode:{C:1}}" />
</rule>
(.+) accessts all the chracter and {UrlEncode:{}} encode the url in the orignal manner.
Regards,
Jalpa

Always redirect from any domain prefix to www.example.com with iis url rewrite rule

we have a site at something.example.com and we want it to go always redirect to www.example.com
We already have the rule in for 'adding' www. when a user just puts example.com.
But we have a test url that is in place for other reasons and we want the live site to ALWAYS redirect to www.example.com no matter what prefix it has before the domain.
just use this regex .* in <match url="" /> or IIS URL re-write pattern field
for additional information:
dot means any single char
Asterix means zero or more of a char
so .* means zero or more of any char
According to your description, I suggest you could try to use {http_host} to match the domain part in the url rewrite rule.
Details, you could refer to below rules:
<rule name="rediect" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^(.*).example.com" />
<add input="{HTTP_HOST}" pattern="^example.com" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:0}" />
</rule>

IIS Domain rewrite to subfolder (only home page)

I want my domain homepage to be redirected to one of my mvc directories
this is the rule i am using
<rule name="Home" stopProcessing="true">
<match url="^/*$" />
<action type="Rewrite" url="/test/" logRewrittenUrl="true" />
</rule>
Same rule is working if i put redirect. But rewrite is not working.
Other URLS should be served normally. Only home page should be rewritten
Can we achieve this without ARR?
//www.example.com should be rewritten to //www.example.com/test/
www.example.com/buy should be served as it is.
Your regex is incorrect. Correct rule is:
<rule name="Home" stopProcessing="true">
<match url="^$" />
<action type="Rewrite" url="/test/" logRewrittenUrl="true" />
</rule>
And this rule will work without ARR because you rewriting to a subfolder in the same website. If you want to rewrite to the different website in IIS, then you need ARR.

IIS URL Rewrite root only

I have 2 URLs
http://test.mysite.com (1) and
http://test.mysite.com/app (2)
I would like to redirect requests to (1) to www.othersite.com
when (2) shuld not be redirected.
Is it possible to do with url rewrite using regex?
br
Yes, it is possible with URL rewrite module. Your rule looks like that:
<rule name="Redirect non app" stopProcessing="true">
<match url="^app(.*)" negate="true" />
<action type="Redirect" url="http://www.othersite.com{REQUEST_URI}" />
</rule>

Resources