I'm trying to do a simple redirect from the www subdomain to the root domain. After trying many variations, I'm stuck and hoping for help. Feeling sure it's something stupid, but can't see it. Here's the rule I'm using.
<rewrite>
<rules>
<rule name="Redirect to root" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.stitchamerica.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://stitchamerica.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
Input greatly appreciated.
This works for me:
<rewrite>
<rules>
<rule name="Remove WWW" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
</conditions>
<action type="Redirect" url="http://YOURSITE.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
Related
My URL HTTP to HTTPS rewrite does not work when there is the character '&' in the URL.
A 410 page not found results.
An example that results in a 410 is...
http://curtainsmadesimple.co.uk/1062/Rapture-&-Wright/Rapture-&-Wright-Collection-Roomshots
OR
http://www.curtainsmadesimple.co.uk/1062/Rapture-&-Wright/Rapture-&-Wright-Collection-Roomshots
However if the '&' is replaced by 'and' in the above URLs the page loads correctly.
I have two rules to rewrite HTTP to HTTPS. One is where there is a non www and the other if there is a www
<rule name="CanonicalHostNameRule1">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.curtainsmadesimple\.co\.uk$" negate="true" />
</conditions>
<action type="Redirect" url="https://www.curtainsmadesimple.co.uk/{R:1}" />
<rule name="Redirect to HTTPS">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
Can anyone tell me why I am getting this issue?
Thanks in advance.
It will work I believe. This is working for me.
<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>
We have the ASP.NET application hosted as Azure WebApp and configured the domain from GoDaddy. We bought SSL for non-www domain. We used the following redirection rule:
<rewrite>
<rules>
<rule name="Redirect to Example.com">
<match url="(.*)"/>
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!^Example.com)" />
</conditions>
<action type="Redirect" url="https://Example.com/{R:1}"/>
</rule>
<rule name="Redirect to https">
<match url="(.*)"/>
<conditions>
<add input="{HTTPS}" pattern="Off"/>
<add input="{REQUEST_METHOD}" pattern="^get$|^head$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}"/>
</rule>
</rules>
</rewrite>
Is there a way to add another rule to redirect request to "https://www" to "https://"?
Thanks,
Jay
I had a similar challenge with my Windows hosting since I have a wildcard cert and host a few subdomains. Here's the web.config I put together, give it a shot and let me know! It seems to work great for me, but my site is extremely simple.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<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>
<rule name="remove www" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.YourDomain\.com$" />
</conditions>
<action type="Redirect" url="https://YourDomain.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I want to write rewrite rule for full URL like
<rule name="r1" stopProcessing="true">
<match url="abc.com/man/mostpopulararticles/brides.aspx" ignoreCase="true" />
<action type="Redirect" url="abc.com/man.aspx" />
</rule>
is it possible. I have tried but it didn't work for me. Is there any other way to do so. Please help me.
<rule name="r1" stopProcessing="true">
<match url="^man/mostpopulararticles/brides.aspx$"/>
<action type="Redirect" url="abc.com/man.aspx" appendQueryString="false" redirectType="Permanent"/>
</rule>
It will be http:// and abc.com as it is not allowing me to enter the url.
Something like this works in my code.
here is the code worked for me:
<rule name="Uk1" stopProcessing="true">
<match url="^man/mostpopulararticles/brides.aspx" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www.)?abc.co.uk$" />
</conditions>
<action type="Redirect" url="/man.aspx" />
</rule>
Thanks All
I have found the following code which will redirect all my traffic to https:
<system.webServer>
<rewrite xdt:Transform="Insert">
<rules>
<rule name="RedirectToHTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
Is it possible to add an "exclusion" to this rule somehow?
I would like a particular path not to be redirected if possible
For example I would like everything below http://www.example.com/desktopmodules/ not to redirect.
Can it be done please?
You can add a rule above it which matches your exclusion pattern, ensuring that the stopProcessing="true" is set on the rule, but with no action:
<system.webServer>
<rewrite xdt:Transform="Insert">
<rules>
<!-- Prevent redirection of URLs matching this pattern -->
<rule name="ExcludeRedirectToHTTPS" stopProcessing="true">
<match url="^desktopmodules.*" />
<action type="None" />
</rule>
<rule name="RedirectToHTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
I have found this bit of web.config code for checking the url to see if its missing the www. if it is then it redirects the user to the www. url
<rewrite>
<rules>
<clear />
<rule name="WWW Rewrite" enabled="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9]+)$" />
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
however i need to do the opposite and i have been hacking around with it (im not very good with regular expressions, no matter how much i try) to try and get it to see if the url has www then redirect it to the non www
reason being is i have a subdomain
trade.words.co.uk
but i want to make sure they dont go to www.trade.words.co.uk
Thanks for any help in advance
Try this:
<rewrite>
<rules>
<clear />
<rule name="WWW Rewrite" enabled="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?:www\.)([.a-zA-Z0-9]+)$" />
</conditions>
<action type="Redirect" url="http://{C:1}/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
I guess you just need the opposite web.config rule using an extended regular expression to match proper url like the following :
<rewrite>
<rules>
<clear />
<rule name="WWW Rewrite" enabled="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^([\w-]+://?|www[.])([^\s]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))$" />
</conditions>
<action type="Redirect" url="http://{R:2}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
Hope this helps