I have been asked to set up a redirect from:
https://www.#####.co.uk/news/uk-families-have-more-money%E2%80%93butalso-more-debts/
TO
https://www.#####.co.uk/news/
I have added the following rule to my web config:
<rule name="Redirect" stopProcessing="true">
<match url="news/uk-families-have-more-money%E2%80%93butalso-more-debts/" />
<action type="Redirect" url="http://#######.co.uk/news/" redirectType="Permanent" />
</rule>
But it is not having any effect.
I know '%E2%80%93' for UTF8 represents '-', so I have tried substituting for that, but the rule is still not having an effect.
Any ideas? Is there anyway I can debug this?
Related
I have an ASP.Net website, but several domain names are pointing to the same website.
so for example lets say i have following domains
www.myMainDomain.com
www.mySite1.com
www.mySite2.com
I have 1 actual website with all the pages and subpages i want to have.
www.myMainDomain.com
www.myMainDomain.com/site1
www.myMainDomain.com/site1/products
www.myMainDomain.com/site2
www.myMainDomain.com/site2/products
...
So i would like to have a rewrite rule in my web.config
so that if the user is coming from the www.myMainDomain.com, it is just the normal site as it is existing
but if they are coming from www.mySite1.com, the rewrite rule should kind of take them to www.myMainDomain.com/site1, and if they go to a subpage, like products, it is always rewritten so like this
www.mySite1.com -> www.myMainDomain.com/site1
www.mySite1.com/products -> www.myMainDomain.com/site1/products
I have something like that, but this is not working, and it is actually causing a 500 Error
<system.webServer>
<rewrite xdt:Transform="Insert">
<rules>
<rule name="Root Hit Redirect" stopProcessing="true">
<match url="^$" />
<action type="Redirect" url="/site1/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
What could be a correct solution?
I think you could use the inverse of standard canonicalhostname redirect with some changes:
<rule name="CanonicalHostNameRule_Mod" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^www\.mySite1\.com$" />
</conditions>
<action type="Redirect" url="http://www.myMainDomain.com/site1/{R:1}" />
</rule>
In this way you have to make a rule for each secondary domain.
I've got the following url:
inspiratie/color-collections/test/test/S%200502-B/test
And the rewrite rule within the web.config:
<rule name="color2">
<match url="(kleur-en-inspiratie|inspiratie)/color-collections/([\S ^/]+)/([\S ^/]+)/([\S ^/]+)(/)?([\S ^/]*)" />
<action type="Rewrite" logRewrittenUrl="true" appendQueryString="false" url="{R:1}/color-collections/color-detail?colorcollection={R:2}&colorfamily={R:3}&color={R:4}&colorname={R:6}" />
</rule>
After the rule kicks in, the url becomes:
inspiratie/color-collections?colorcollection=test&colorfamily=test&color=S&colorname=
But the expected output would be:
inspiratie/color-collections?colorcollection=test&colorfamily=test&color=S 0502-B&colorname=test
As you can see if the space is used within the color code, the query string is broken after the color param ({R:4}).
When I test the rule within IIS, it works fine and returns the expected results.
I know that the unescaped white space will not work, but expecting the escaped one to work.
In your case problem cause because of encoding. You need to use {UNENCODED_URL} variable for regexp. Rule should be like that:
<rule name="color2">
<match url=".*" />
<conditions>
<add input="{UNENCODED_URL}" pattern="(kleur-en-inspiratie|inspiratie)/color-collections/([\S ^/]+)/([\S ^/]+)/([\S ^/]+)(/)?([\S ^/]*)" />
</conditions>
<action type="Rewrite" logRewrittenUrl="true" appendQueryString="false" url="{C:1}/color-collections/color-detail?colorcollection={C:2}&colorfamily={C:3}&color={C:4}&colorname={C:6}" />
</rule>
I have a help section on a web site, which for now I want it to redirect to another place. The rest of the site should stay the same, which means that only the help section/content should make the user go to another site:
device.domain.net/collection/hgkhghj should return to device.domain.net/collection
I can have anything at the place of hgkhghj . If i am writing device.domain.net/collection then it should return device.domain.net/collection
<rule name="Help Redirect" stopProcessing="true">
<match url="(.*)/collection(.*)" ignoreCase="true" />
<action type="Redirect" url="http:/device.domain.net" appendQueryString="false" redirectType="Permanent" />
</rule>
but currently it is returning to device.domain.net.
I want to make one more Rule in which if i enter device.domain.net/gcfhgg then it should return to device.domain.net.
<rule name="Help Redirect" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<action type="Redirect" url="http://device.domain.net" appendQueryString="false" redirectType="Permanent" />
</rule>
But it is not working.
For your first rule you could use the following (assuming it is on the same domain):
<rule name="Help Redirect" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^collection/(.*)" />
<action type="Redirect" url="collection" appendQueryString="false" redirectType="Permanent" />
</rule>
If this is on another domain you will need ARR installed as well. Your second rule is more complicated as it looks as if you are attempting to perform a redirect only if you hit a 404 page. This is something I have never done using rewrite rules. Is there a reason for doing this as opposed to showing a custom 404 page?
I have to route all the requests on my site from http to https, I was succesfull in doing that by adding another class in Global.Asax.Cs
// working part for redirecting http into https
protected void Application_BeginRequest()
{
if (!Context.Request.IsSecureConnection)
Response.Redirect(Context.Request.Url.ToString().Replace("http:", "https:"));
}
But before that I tried by inserting Rules into WebConfig
<rewrite>
<rules>
<rule name="Redirect HTTP to HTTPS" stopProcessing="true">
<match url="(.*)"/>
<conditions>
<add input="{HTTPS}" pattern="^OFF$"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther"/>
</rule>
</rules>
</rewrite>
Which is not working, But I have seen many posts here which say that Rules is the best way to route request, I have also installed URL Rewrite on my server . Cany any one please suggest why it wasnt working ( i am getting 500 internal server error).
Does rerouting in Global.asax affect performance when there is a huge volume of requests.
Please advice
I use this rule and it works like a charm:
<system.webServer>
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
without any datailed info about the error i can only guess that your web.config is malformed or you put the rule section in the wrong place or URL Rewrite Module is not installed correctly
I have the following code in my web-config to be able to redirect both the URLs with the prefix "www" and non-SSL requests to the https:// mydomain.com because the SSL certificate is registered to the domain without the www
<rewrite>
<rules>
<rule name="Remove WWW prefix and redirect to https" >
<match url="(.*)" ignoreCase="true" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" ignoreCase="true" />
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://mydomain.com/{R:1}" />
</rule>
</rules>
</rewrite>
This is the result:
1) http:// mydomain.com/something --> https:// mydomain.com/something (Correct)
2) http:// www.mydomain.com/something --> https:// mydomain.com/something (Correct)
3) https:// www.mydomain.com/something --> Shows certificate error (There is a problem with this website's security certificate.)
When you select "Continue to this website (not recommended)." on the certificate error page, the url is rewritten correctly (https:// mydomain.com/something)
How can I make sure the certificate error does not show?
Thank you
One way to solve it is to register two separate rules:
Remove www.
Force HTTPS.
<rule name="Remove www" stopProcessing="true">
<match url="(.*)" negate="false"></match>
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.(.*)$" />
</conditions>
<action type="Redirect" url="https://{C:1}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="Force HTTPS" enabled="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
so we use this in our projects, and this works.
Let me know it that helps:
<rewrite>
<rules>
<rule name="Redirect to https">
<match url="(.*)"/>
<conditions>
<add input="{HTTPS}" pattern="Off"/>
<add input="{REQUEST_METHOD}" pattern="^get$|^head$" />
<add input="{HTTP_HOST}" pattern="localhost" negate="true"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}"/>
</rule>
</rules>
</rewrite>
It also ignores the request when you access the site on your local machine.
I'm not sure about this as I don't have too much experience with url-rewriting but trying to help wont hurt.
You can try this
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://mydomain.com/{R:1}" redirectType="Permanent" />
I googled quite a lot and found this but it might not do what you meant to.
This problem cannot be solved by using rewrite rules: the problem is that the certificate is verified at the time the connection to the server is set up. As your server does not have a valid certificate for the www. variant, the certificate is invalid and the browser will notify its user.
Only after the user agrees to continue, the request is sent to the server and the rewrite rules kick in.
I'm seeing the same problem. Because the domain doesn't have an SSL certificate for www, the web.config code doesn't remove the www when the URL includes https. The result is using http with or without the www, correctly redirects it to https://domain, but if it starts with https: and www, it's stuck.
So can this be resolved at the DNS level so that www isn't defined as a CNAME and is just redirected there? Google Domains seems to have synthetic records for this. Has anyone used it successfully?