I have a strange problem with IIS url_rewrite module and web.config setup. I think there is a problem with the matching pattern or I'm doing something completely wrong..
My setup is a ASP.Net MVC app with multi language support. For starters I have three languages enabled, English, German and French.. so you could access them with a language parameter www.domain.com/en/ www.domain.com/de/ www.domain.com/fr/.. now I bought a german domain and setup up the german part of the page to .de domain, so now I have www.domain.com/en/ www.domain.de/de/ www.domain.com/fr/ everything ok so far..
The problem i'm trying to figure out how to add a safe 301 redirect if you write www.domain.com/de/ to www.domain.de/de/ or vice versa www.domain.de/en/ back to www.domain.com/en/ ... the main reason i wan't to solve this its because of SEO to fix the duplicate content issues ..
I have IIS 8.5, url_rewrite module installed and now I'm stuck with this in the in my web.config
<rule name="DE Redirect" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^www\.domain\.com\/de\/$" />
</conditions>
<action type="Redirect" url="https://www.domain.de/de/{R:0}" redirectType="Permanent" />
</rule>
I want to redirect the user if they enter or get to www.domain.com/de/page1 to www.domain.de/de/page1 and only if there is the www.domain.com/de/ in the url, I won't redirect if they enter to english of french language website.
Any idea what am I doing wrong or what is the best way to debug such redirects.. I have tried with the Failed Request Tracing but didn't found anything helpful.
Any ideas?
Cheers
Because answers cannot contain domain.com, then I will use everywhere example.com and example.de
You should use redirect like that:
<rule name="DE Redirect" stopProcessing="true">
<match url="^de/(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.example\.com$" />
</conditions>
<action type="Redirect" url="https://www.example.de/de/{R:1}" redirectType="Permanent" />
</rule>
Also if you want to prevent opening the French language on German domain https://www.example.de/fr and redirect it to https://www.example.com/fr then you should also add
<rule name="FR Redirect on DE domain" stopProcessing="true">
<match url="^fr/(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.example\.de$" />
</conditions>
<action type="Redirect" url="https://www.example.com/fr/{R:1}" redirectType="Permanent" />
</rule>
Related
I have a sitecore website with a default URL structure http:/ /www.domain.com/language/country/abc/xxx/........ due to SEO friendly we need to have language after country,Any idea if I can reset the format to something else,like http: //www. domain.com/country/language/abc/xxx/......?
can this be done on iis rewrite,if yes how.
thanks in advance
I suggest you specify your language and country so That I can match them in parameters.
Here is a sample for your referenceļ¼
<rule name="test" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{REQUEST_URI}" pattern="^([^/]+)/([^/]+)/(.+)$" />
</conditions>
<action type="Redirect" url="http://[www.domain.com]/{C:2}/{C:1}/{C:3}" />
</rule>
a 3rd party supplier is sending out emails to our clients with an incorrect unsubscribe link. Until they can update this URL I'm looking to correct any requests through web.config.
The correct working link should be:
https://www.example.com/my-account/alertunsubscribe?email=[email]&searchname=[searchname]
The broken link in emails is:
http://www.example.com/property/myaccount/alertunsubscribe?email=[email]&searchname=[searchname]
I've been trying to use something like the following:
<rule name="AlertUnsub" stopProcessing="true">
<match url=".*" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^property/myaccount/alertsubscribe" />
</conditions>
<action type="Redirect" url="https://www.example.com/my-account/alertsubscribe" appendQueryString="true" />
</rule>
Any ideas what I'm doing wrong? I already have another rule re-directing non http traffic to https which works fine so I don't think I have to deal with that here. Same for non-www to www.
Any help would be appreciated.
Thanks
You should look for a match with the URL not {HTTP_HOST} variable, so no condition required.
Try this instead:
<rule name="AlertUnsub" stopProcessing="true">
<match url="^property/myaccount/alertunsubscribe" />
<action type="Redirect" url="my-account/alertunsubscribe" appendQueryString="true" redirectType="Found" />
</rule>
BTW there's a confusion about alertsubscribe and alertunsubscribe in the question. I assume that it is alertunsubscribe.
In IIS 8, I want to redirect the url http://test.example.com to http://www.example.com/abc/123
I try this, but not work.
<rule name="test" stopProcessing="true">
<match url="^test.example.com$" />
<action type="Redirect" url="http://www.example.com/abc/123" />
</rule>
you could add the pattern like this
<rule name="RedirectDomain" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="true">
<add input="{HTTP_HOST}" pattern="(.*)test.example.com />
</conditions>
<action type="Redirect" url="http://www.example.com/abc/123" redirectType="Permanent" />
</rule>
In the IIS GUI on the given side you should be able to choose 'HTTP Redirect' from there you can type in a url to redirect the site to.
I don't know if this approach is the recommended (It is normally used to redirect HTTP request on a given site to use HTTPS), but it will solve your problem.
I need to redirect all https requests to http, for example, if someone visits https://www.example.com/another-page/ to http://www.example.com/another-page/
I have the following rewrite rule in my web.config right now, but it's not working correctly. It's redirecting https://www.example.com/another-page/ to https://www.example.com/, so to the root of the site, but instead I want the redirect to stay in the same URL and only rewrite https to http.
<rule name="Redirect to HTTP" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{R:1}" pattern="^onepage/(.*)$" negate="true" />
<add input="{HTTPS}" pattern="^ON$" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/{R:0}" redirectType="Permanent" />
</rule>
Any help on changing the above rule so that it only changes https to http, but keeps the full url visited would be greatly appreciated!
I set up your rule, cleaned up a little, and it worked; so this isn't really answering with much new.
Suggestion: Remove the onepage input condition just for testing, as cheesmacfly suggested in the question comment.
Also, try changing the action to {R:1} instead of {R:0}. It shouldn't matter in this case, but I just like using 1 and up, to match the specific capturing group. R:0 means the entire matched string, which always confuses me just a little.
<rule name="Redirect to HTTP" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^ON$" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
One possibility is that your browser has cached a previous attempt of your rules. When the redirectType is Permanent, and you're still developing or testing, the browser often caches a previous rule. Clear your browser cache, and/or remove the Permanent, and/or browse in incognito mode. When done testing, change it to permanent. See number 2 and 3 in this answer: https://stackoverflow.com/a/9204355/292060
Please paste the below code in web.config file.
<rule name="Redirect to http" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="http://{HTTPS_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
I am trying to force the use of http on all pages of our site with the exception of a checkout page. I have used the rewrite rule below but it doesn't work with the www sub-domain in the url.
If I use https://domain.com it successfully redirects to http://www.domain.com but if I try https with www nothing happens. Please note that there is also a canonical domain name redirect in place but this issue still happens without this rule.
<rule name="No-https" enabled="true" stopProcessing="true">
<match url=".*" negate="false" />
<action type="Redirect" url="http://{HTTP_HOST}{REQUEST_URI}" />
<conditions>
<add input="{HTTPS}" pattern="on" />
<add input="{URL}" pattern="CheckOut" negate="true" />
</conditions>
</rule>
This has been driving me nuts all morning, I'm hoping someone with more experience of IIS rewrites can give me some help.
Spent a few hours on a similar issue. In my case I'm redirecting traffic from http to https and I want to do the same where sub domains are in use, e.g. http://subdomain.mydomain.com rewrites to https://subdomain.mydomain.com. It seems that for IIS 7.5 at least you need to add a http binding in IIS for each specific subdomain or it will not be picked up by the catch all matching below.
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
</rules>
</rewrite>