On Google there is the following Url
www.domain.ch/House/rent
So now my page is now available in multi language and i have now the language in the url, and it looks like this
www.domain.ch/en/house/rent
So I will redirect all old links with url rewrite in the web.config, but I can't find out the match condition to find out if there is a languege insite the url.
My role:
<rule name="mydomain.com" >
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^(localhost:3005/|localhost:3005/)$" />
</conditions>
<action type="Redirect" url="http://localhost:3005/de/{R:1}" logRewrittenUrl="true" />
</rule>
Thanks for any help!
<rule name="mydomain.com" stopProcessing="true" >
<match url="(.*)" />
<conditions>
<!-- redirect only if the URL doesn't contain /en/ or /de/ already (negate = true)-->
<add input="{URL}" pattern="/en/|/de/" negate="true" />
</conditions>
<action type="Redirect" url="de/{R:1}" />
</rule>
Related
Pretty new to this, but trying hard to understand.
I was able to redirect non-www to www, and http to https, but now I need to redirect a domain pointer to the primary. i.e. Domain2.com to Domain1.com. I am concerned about the URL chain and taking a hit on SEO. Should I put the domain redirect before the WWW\https one?
<rule name="Force WWW and SSL" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^[^www]" />
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://www.domain1.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
<!-- Just add this? Should it go in front of the other? -->
<rule name ="Redirect Domain2 to Domain1" enabled="true">
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="domain2.com" />
</conditions>
<action type="Redirect" url="https//www.domain1.com/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>
Instead two rules you can create one rule with multiple conditions:
<rule name="All in one rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="off" />
<add input="{HTTP_HOST}" pattern="^www\.domain1\.com$" negate="true" />
</conditions>
<action type="Redirect" url="https://www.domain1.com{URL}" />
</rule>
This rule will do the following:
Redirect all other domains (domain1.com, domain2.com and etc) to www.domain1.com
Redirect HTTP to HTTPS
This rule will make only one necessary redirect instead of multiple redirects as your current rules
the need is to redirect every non www hit to www urls and for doing that i have following rule
<rule name="WWW" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^domain\.com$" />
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:1}" />
</rule>
what is does right now- it redirects every hit of non www url to my home page (www.domain.com)
Expected- it should redirect domain.com/subpage to www.domain.com/subpage
you can try this,it's work for me
<rule name="www" >
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example\.com" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}" redirectType="Permanent" />
</rule>
the problem was with my New HAProxy LB cluster which was doing some sort of redirection with its own, redirect rule is fine. fixed it with the help of IT
How would I modify this rule to include non-www to www redirect?
<rule name="Force Https" stopProcessing="true">
<match url="healthcheck.html" negate="true" />
<conditions>
<add input="{HTTP_X_FORWARDED_PROTO}" pattern="https" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>
Is there a better way to force HTTPS sitewide? I am using ASP.NET MVC 5 on IIS 8.5
I think you just need to add another rule where it checks if the HTTP_HOST variable just contains your host without the www. prefix, and redirect if so:
<!-- You first rule. Note stopProcessing is now false. -->
<rule name="Force Https" stopProcessing="false">
<match url="healthcheck.html" negate="true" />
<conditions>
<add input="{HTTP_X_FORWARDED_PROTO}" pattern="https" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>
<!-- Additional rule. -->
<rule name="Force WWW" stopProcessing="true">
<match url="healthcheck.html" negate="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^yourdomain\.com"/>
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://www.{HTTP_HOST}{REQUEST_URI}" />
</rule>
Just change yourdomain.com above to your actual host domain name.
To answer your other question, I think URL redirect (through URL Rewrite) is the simplest way to force HTTPS without returning a 403 to your users who still try to access your site via HTTP.
UPDATE
In response to your comment regarding the double 301, you could try this single rule. I do not have my laptop at home to verify, but I think this will work:
<!-- This rule will capture any http request regardless of the 'www.' prefix in the URL -->
<rule name="Force Https" stopProcessing="true">
<match url="healthcheck.html" negate="true" />
<conditions>
<add input="{HTTP_X_FORWARDED_PROTO}" pattern="^http$" />
</conditions>
<action type="Redirect" url="https://www.yourdomain.com{REQUEST_URI}" redirectType="Permanent" />
</rule>
<!-- This rule will capture https request that does not have the 'www.' prefix in the URL -->
<rule name="Force WWW Prefix" stopProcessing="true">
<match url="healthcheck.html" negate="true" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_X_FORWARDED_PROTO}" pattern="https" />
<add input="{HTTP_HOST}" pattern="^yourdomain\.com$"/>
</conditions>
<action type="Redirect" url="https://www.yourdomain.com{REQUEST_URI}" redirectType="Permanent" />
</rule>
I have the following redirect rules one is for non www url (http://mysite.co.uk/....) and the other is for a www URL to redirect to http://www.mysite2.co.uk/...
Currently the rules are a catch all. I don't want the rules to execute if a certain URL is hit which contains "/mystring/mystring.aspx".
Can anyone help me write the rules for this?
<rule name="Canonical Host Name - mysite" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?:www|[^.]+\.)*mysite\.co.uk$" />
</conditions>
<action type="Redirect" url="http://www.mysite2.co.uk/{R:1}" redirectType="Permanent" />
</rule>
<rule name="Canonical Host - mysite 2" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.mysite\.co.uk$" />
</conditions>
<action type="Redirect" url="http://www.mysite2.co.uk/{R:1}" redirectType="Permanent" />
</rule>
You should be able to accomplish this by adding to the conditions, and using negate="true". Something like this:
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^(?:www|[^.]+\.)*mysite\.co.uk$" />
<add input="{PATH_INFO}" pattern="mystring\/mystring\.aspx" negate="true" />
</conditions>
I have added this rule in my web.config to redirect non www URLs to www.
<rule name="Redirect to WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:0}" redirectType="Permanent" />
</rule>
Although it is working fine for main site URL. Like if user types http://example.com it redirects to http://www.example.com
But for some URLs like
http://www.example.com/userfiles/abc.pdf
it redirects to
http://www.www.example.com/userfiles/abc.pdf
Here you can see 2 time www in URL.
I guess this one should work:
<rule name="Redirect to WWW" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.example\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}" />
</rule>
If this one does not work as expected, you could try to add another condition:
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
Hope this helps.