IIS 10 URL redirect from one domain to another - redirect

I would like to redirect a specific site from one domain to another and i have tried the following URL redirect. Not sure where i am going wrong.
I have an app at http://www.a.b.com/myapp/index.aspx
I would like to redirect it to
http://www.a.c.com/myapp/index.aspx
<rule name="testredirect" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^myapp/index.aspx$" />
<action type="Redirect" url="http://www.a.c.com/{R:0}" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.a.b.com$" />
</conditions>
</rule>

The rule work perfectly on my side. Please try to clean browser cache and post your detailed error message. Please ensure you are running the rule in the right place and has been enabled.
Besides, please check whether the incoming request is reaching the correct application pool.

Related

Restrict requests by HTTP referer - IIS

I have an IIS website at mydomain.com/mywebsite which has a URL rewrite request that for any requests to a 'maps' path (mydomain.com/mywebsite/maps) through the website, it will redirect requests to an external site to retrieve mapping image tiles that display on the page.
If someone tries to go to mydomain.com/mywebsite/maps on their browser, I do not want it to be accessible as I want to restrict these requests only to the website.
How can I set up a restrict rule in IIS to configure this?
You can try to create a request blocking rule for this, here a example for you as reference:
<rule name="RequestBlockingRule1" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{URL}" pattern="^maps$" />
</conditions>
<action type="AbortRequest" />
</rule>
I have managed to restrict access to the URL path by adding an HTTP_REFERER condition in my URL inbound rewrite rule so it only accepts requests from my website domain which seems to work.
<conditions>
<add input="{HTTP_REFERER}" pattern="*mywebsite.com*" />
</conditions>

How do I solve a 403 or redirect error in IIS Manager

403 or redirect error keeps appearing in the browser even though I have done my redirects properly in IIS Manager. I have tried clearing my cookies, this did not work.
Edit: enabled direct browsing in IIS Manager and this is the result (the fifth image)
redirect checked
result of redirect checked
redirect not checked
result of redirect not checked
result of enabling direct browsing
Try to use the redirect function in the URL Rewrite module:
<rewrite>
<rules>
<rule name="Test" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP}" pattern="off" />
</conditions>
<action type="Redirect" url="http://www.example.com" />
</rule>
</rules>
</rewrite>
If you haven’t installed URL Rewrite yet, you can download URL Rewrite from this link.

iis web.config redirect certain domain/path to a new domain/samepath

I need to use web.config to setup a redirect for a certain path/folder to a new domain using the same original path/folder.
Ex:
If www.domain1.com/path2match1/* is detected then redirect to:
www.newdomain.com/path2match1/* (same path as matched on domain1)
ex:
current: www.domain1.com/path2match1/someFileOrFolders/somefile.html
redirect to: www.newdomain.com/path2match1/someFileOrFolders/somefile.html
Any help would greatly be appreciated
thanks
I managed to find an answer for my question on my own! (Yay for me! haha)
Anyways,
Here's how to do what I was asking:
<rewrite>
<rules>
<rule name="NAME" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}{REQUEST_URI}" pattern="(.*)/FOLDER/(.*)" />
</conditions>
<action type="Redirect" appendQueryString="false" url="http://DESTINATION-URL.TLD/FOLDERS/{C:2}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
Caution! Adding multiple or tag set or placing this code in the wrong location will cause the site to generate internal server errors, making it unavailable for visitors until the additional tags are removed.
NAME can be anything, as long as it is unique
/FOLDER/ is the folder you are redirecting from
http://DESTINATION-URL.TLD/FOLDERS/ is where you are redirecting to.

Creating a IIS Url Rewrite/Redirect

Im struggling to get a url rewrite/redirect to work in IIS. I've installed the url rewrite module and all the rules fail to do anything. Here is the scenario, we want all web requests which generate a report to be pushed off to a secondary server so it doesn't harm the main box. The web requests that generate reports look something like this:
http://mywebaddress/api/Actionname=GenerateReport&param=123
So im wanting to do some type of regex check on finding any web requests that have "GenerateReport" in it and redirect it to something like:
http://mywebaddressofsecondserver/api/Actionname=GenerateReport&param=123
Any ideas on how the redirect/rewrite would go for this?
You need to check if REQUEST_URI contains Actionname=GenerateReport.
If so, you'll redirect it to other webserver url equivalent.
Translated to an IIS rewrite rule, it would look like this
<rule name="Delegate report generation" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{REQUEST_URI}" pattern="Actionname=GenerateReport" />
</conditions>
<action type="Redirect" url="http://mywebaddressofsecondserver/{R:1}" />
</rule>
Thanks, Justin Iurman,
Your answer solved my issue of getting methods
http://mywebaddress/api/Param/Action1
http://localserverwithport/api/Param/Action1
but for below Post methods it's still giving 404 not found
http://mywebaddress/api/Param/PostAction2
http://localserverwithport/api/Param/PostAction2
Post parameters are:
{"Param1":"James","Param2":"jani"}
My implementation is
'<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite Rule1" >
<match url="^(.*)" />
<action type="Redirect" url="http://localserverwithport/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>'

301 Redirect one domain to another using web.config

I have multiple domains pointing to one hosting location.
I wish to establish one of the domains as my main domain and therefore I wish to perform a 301 redirect to this main domain whenever a user accesses my site from a secondary domain.
For example:
www.example.com
This is my main domain. I want all other domains associated with my site to redirect to here.
If a user comes in on:
www.test.com or
www.test.com/anypage
etc.
Then I want the user to be redirected to the example version of that page.
How do I do this using the web.Config file of my application? The reason I ask is that usually my web hosting provider has a tool in their back office that allows me to setup this redirect however, our client has opted for a different hosting provider that do not provide such a tool.
I have attempted to do this redirect using the following code but it doesn't seem to work:
<rule name="Canonical Host Name" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^test\.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}}" redirectType="Permanent" />
</rule>
My application is an Umbraco powered site and so has several system.webServer entries in the web.config file. It may just be the case that I have entered this code in the wrong place but any help here would be greatly appreciated as I am only used to doing 301 redirects in .htaccess files.
This is not really that umbraco related but I think what you want to do is this:
<rewrite>
<rules>
<rule name="redirect" enabled="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^www\.example\.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
Match all urls unless the host name part is exactly www.example.com - and redirect those to www.example.com/whatever.