IIS Domain rewrite to subfolder (only home page) - iis

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.

Related

IIS and URL Rewrite for landing pages and simple URLs

Right now we have a bunch of extra directories with an index.htm in them that handle redirects to pages within our application. Instead of littering our folder structure with these, is there a way to us URL rewrite to redirect a user without completely breaking 404 errors?
For example,
domain.com/login
Would redirect to
domain.com/user/accountLogin.htm
Or
domain.com/happypartnercompany
Could go to
domain.com/partners/about.xyz?partner=123
For anyone else looking for a simple example, this is what I ended up doing:
<rule name="members" stopProcessing="true">
<match url="^members*$" ignoreCase="true" />
<action type="Rewrite" url="index.xyz?m=home/members/list" />
</rule>
And to actually redirect the user:
<rule name="member_signup_1" stopProcessing="true">
<match url="^sefcu*$" ignoreCase="true" />
<action type="Redirect" url="index.xyz?m=signup/enroll&partnerid=8532" />
</rule>
Ampersands must be escaped with & in the URL.

Can anyone help me consolidate these IIS rewrite rules?

I've got some IIS rewrite rules in place, and everything is working fine. But i feel like i can consolidate them.
Here are my rules:
<rule name="Blog - Advice - root" patternSyntax="ExactMatch" stopProcessing="true">
<match url="advice" />
<action type="Rewrite" url="https://mysite.wpengine.com/advice" />
</rule>
<rule name="Blog - Advice - root (with slash)" patternSyntax="ExactMatch" stopProcessing="true">
<match url="advice/" />
<action type="Rewrite" url="https://mysite.wpengine.com/advice" />
</rule>
<rule name="Blog - Advice" stopProcessing="true">
<match url="^advice/?(.*)" />
<action type="Rewrite" url="https://mysite.wpengine.com/advice/{R:1}" />
</rule>
I want to match the following examples:
/advice
/advice/ (should rewrite without the slash)
/advice/sdfsdf
/advice/sdfsdf/ (should rewrite without the slash)
/advice/sdfdsf/sdfds
Can it be done with 1 (or 2) routes?
If i leave the second one out for example, Wordpress (the site i'm rewriting to), will do a 301 redirect to a URL without the slash, and i lose the rewrite since the URL is changed again. (so i end up at mysite.wpengine.com/advice, which is wrong).
So i need to make sure any rewrites don't involve a redirect on the target site end.
Many thanks :)

IIS Url Rewrite to another server

I have an old url www.mydomain.com/customer/1. I changed that server to ww2 and it displays fine at ww2.mydomain.com/customer/1. On my new IIS 8.5 www server how can I put in a rewrite rule so if the user goes to www.mydomain.com/customer/1 they will redirect to ww2.mydomain.com/customer/1. I have tried numerous patterns in the Url Rewrite 2.0 module and nothing seems to work. All other www requests I do not want redirected, those stay on my new www server.
I you want to redirect a single path, /customer/1, then you should add this to Web.config on the www.mydomain.com server:
<rewrite>
<rules>
<rule name="Redirect 'www.mydomain.com/customer/1' to 'ww2.mydomain.com/customer/1'" stopProcessing="true">
<match url="^customer/1$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.mydomain\.com$" />
</conditions>
<action type="Redirect" url="http://ww2.mydomain.com{REQUEST_URI}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
If you wish to include additional paths, you can fiddle with the RegEx specified in the <match url="^customer/1$" /> tag.

IIS - Redirect all requests from one domain to a specific folder

I have a website configured on IIS and multiple domains configured on my hosts file to point to my localhost.
My problem is that I need to redirect all the requests from:
http://domain.com/folder/ to http://domain.com/
So a request for
http://domain.com/folder/test/image.jpeg should be transformed into:
http://domain.com/test/image.jpeg
I can't change the files because I'm trying to emulate a cdn behavior.
Can anyone help?
Thanks
Joao
Using the rewrite module, you can go with:
<rule name="skip folder" stopProcessing="true">
<match url="^folder/(.*)$" />
<action type="Redirect" url="{R:1}" />
</rule>
The default redirect is a permanent (301).
If you want to keep the url http://domain.com/folder/test/image.jpeg but display the content http://domain.com/test/image.jpeg, then a rewrite has to be used:
<rule name="skip folder" stopProcessing="true">
<match url="^folder/(.*)$" />
<action type="Rewrite" url="{R:1}" />
</rule>

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