IIS does not redirect to external domain (web.config) - redirect

I wrote a rule to redirect all files to be served from a new domain :
<rule name="Redirect files" stopProcessing="false">
<match url="^/?subdirectory/files(/.*)?$" ignoreCase="true" />
<action type="Redirect" url="https://newDomain{R:1}" />
</rule>
What I'm expecting for a URL like :
https://oldDomain/subdirectory/files/file.png
To be redirected to
https://newDomain/file.png
But what I get is :
https://oldDomain/file.png
No matter what I try, it's always under the oldDomain, I tried to move this rule to the end of the rules list, but it does not work!

I checked your rule and it looks 100% correct. Most probably your browser cached 301 redirect. All that you need to do is clear your cache in browser

Related

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.

Web.config mass 301 redirect old news page to a slightly different Urls

I need to redirect a bunch of news articles to a different url format using web.config.
For example, this Url:
https://www.example.com/footer/press-resources/press-releases/press-release-detail/abcd-press-release-item
Should be redirected to this Url:
https://www.example.com/about/press-releases/press-release-detail/abcd-press-release-item
In this example, as you can see this portion of the Url is staying intact /press-release-detail/abcd-press-release-item but everything else before this should be redirected. The only dynamic part of the Url is the article's title which is at the end of the Url, in this case: abcd-press-release-item
I have about 300 items, obviously redirecting them one by one is going to take some time. Is there a way to rule them all out and mass redirect the old Urls to the new ones?
This is a Windows/IIS server with a .NET CMS and a web.config file.
I tried this rule and it didn't work for me:
<rule name="301 Redirect 1" stopProcessing="true">
<match url="^https://www.example.com/footer/press-resources/press-releases/press-release-detail\$" />
<action type="Redirect" url="https://www.example.com/about/press-releases/press-release-detail" redirectType="Permanent" />
</rule>
Try to use this URL Rewrite rule:
<rewrite>
<rules>
<rule name="Test" stopProcessing="true">
<match url="(footer)/(press-resources)(.*)" />
<action type="Redirect" url="https://www.example.com/about{R:3}" />
</rule>
</rules>
</rewrite>

IIS 10 URL redirect from one domain to another

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.

Fixing 301 redirect rules to not be seen as not found IIS8.5 ASP.NET

I am getting 404 when trying to access domain like https://www.example.com I get 404.
I have the following rewrite rules:
<rules>
<rule name="Redirect-HTTP-HTTPS-IIS">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
<rule name="CanonicalHostNameRule1">
<match url="(.*)"/>
<conditions>
<add input="{HTTP_HOST}" pattern="^example\.com$" negate="true"/>
</conditions>
<action type="Redirect" url="https://example.com/{R:1}"/>
</rule>
</rules>
Accessing https://www.example.com will get eventually to https://example.com. My problem is that some serves like Google webmaster tools validation can't verify the site because the page returns not found, although at the end it redirects to https://example.com.
http://example.com does show 301 redirect to https://example.com. It's only when I add www it doesn't show 301 redirect, although the server doe eventually redirects it to the right location.
How changes to the write rules I need to make so accessing https://www.example.com will be recognize as 301 redirect to https://example.com. I think that because of the multiple rules the page send not found.
Maybe there is a way to write it as a single rule that redirects 301 that includes both rules, so it will redirect URLs with HTTP or/and WWW to the one with HTTPS and non-WWW URLs.
Update: I inspected chrome Network and in the Status column, it say (canceled) for type Document and it shown on red. It might be due to IIS returning 404 because the HTTPS for domain with WWW is not certified. Is there any way around this?
Using IIS8.5 / ASP.NET 4.5
Thanks.
I needed to create an SSL certificate for the WWW version of the site as well. Once I did it, the redirection worked as intended.

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>'