301 redirect - Redirect parent but not for its children. For IIS version 10 Windows 2019 - redirect

I am trying to figure out how to make sure the 301 redirect will work only on the parent and its children.
The children should have the same URLs.
Here is the code in the web.config:
<rule name="Rewrite Change of my parent page" stopProcessing="true">
<match url="^my_old_parent$" ignoreCase="false" />
<action type="Redirect" url="/New-Parent-Page/" redirectType="Permanent" />
</rule>
I tried different variations and nothing worked.
I looked at this thread:
301 redirect - Redirect parent but not it's children
They mentioned to use RedirectMatch instead of Redirect and it did not work for IIS.
I appreciate an idea of which code to use for IIS 10.
Thanks,
Doron
When tried RedirectMatch I got an error message.

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.

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

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

asp.net MVC And I need to setup 301 redirects

I have a site moving from php to asp.net MVC And I need to setup 301 redirects for it so like www.mystoresitem.com/products/widget1name needs to redirect to www.mystoresitem.com/widget1name for 700+ different widgets how do I redirect this with out doing it for each product/widget.
First of all you need to be sure that you installed URL Rewrite module in your IIS
Then in your web.config just add this rules inside system.webServer section:
<rewrite>
<rules>
<rule name="Redirects to products">
<match url="^products/(.*)" />
<action type="Redirect" url="/{R:1}" />
</rule>
</rules>
</rewrite>
It will automatically redirect all your urls
www.mystoresitem.com/products/{productname} to www.mystoresitem.com/{productname}

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.

How to make an aspx page do a httpredirect?

I'm trying to redirect an aspx page to another aspx page. But only as the aspx page get's called without any parameters.
So when it's called like this: https://www.a.com/test.aspx?param=1 it doesn't have to do anyhthing.
But when it's called like this: https://www.a.com/test.aspx it has to redirect.
I tried this, but it doesn't redirect, instead, it executes the aspx.
<system.webServer>
<httpRedirect enabled="true" httpResponseStatus="Found" exactDestination="true">
<add wildcard="*test.aspx" destination="/destination.aspx"/>
</httpRedirect>
</system.webserver>
Any ideas?
extra info: it's from a https domain.
I also tried the following, but this makes it crash hard:
<rewrite>
<rules>
<rule name="myrule" stopProcessing="true">
<match url="/test.aspx" />
<action
type="Redirect"
url="/destination.aspx"
appendQueryString="false"
redirectType="Found" />
</rule>
</rules>
</rewrite>
One way to do it would using code in the page load of your ASPX page. If no querystring are provided, then do your redirect.
If you want to do the redirect earlier, you can also use the global.asax BeginRequest event to redirect (check the current request's URI and redirect if needed).