Rewrite URL causes infinite loop - https

In IIS 7, I want to force all pages to go to https by adding the following to my web.config but this causes infinite loop.
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" enabled="true" 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>
I have tried to disable rule on all virtual directories/application as suggested here, http://blogs.msdn.com/b/kaushal/archive/2013/05/23/http-to-https-redirects-on-iis-7-x-and-higher.aspx, with no luck. Does anyone have any idea why? Thank you!

Related

How to use web.config to overwrite redirect rule for a file with same name but different extension?

I have an existing web.config file to redirect a page titled privacy.asp to privacy (without the .asp extension). It works as it should.
I now have a client who had a file privacy.html and I want to send a httpResponseStatus of permanent, that being /privacy.
Here is what I tried but when pulling up the privacy.html it resolves with the .html extension but the actual page is that of the .asp.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<location path="privacy.html">
<system.webServer>
<httpRedirect enabled="true" destination="/privacy/" httpResponseStatus="Permanent" />
</system.webServer>
</location>
<system.webServer>
<rewrite>
<rules>
<rule name="privacy" stopProcessing="true">
<match url="^privacy" />
<action type="Rewrite" url="privacy.asp" />
</rule>
</rules>
</system.webServer>
</configuration>
You could use below rewrite rule:
<rule name="privacy" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_URI}" pattern="privacy.html$" />
</conditions>
<action type="Redirect" url="privacy" appendQueryString="false" />
</rule>
<rule name="rewrite rule" stopProcessing="true">
<match url="privacy$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="privacy.asp" appendQueryString="false" logRewrittenUrl="true" />
</rule>
Note: do not forget to remove the location path and old URL rewrite rule.
Rregards,
Jalpa

HTTPS negate not working

I have this site "localhost". I want all pages should have https except "localhost/order.aspx?r=15". problem here is it redirect all pages to HTTPS including "localhost/order.aspx?r=15". I have also tried the pattern like
"^/localhost/order.aspx$"
<rule name="Force HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{REQUEST_URI}" pattern="(order.*)" ignoreCase="true" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
So I fixed it.
Clear Browser cache, as often time browser remember the HTTPS path. and tries to retrieve the HTTPS even if you provide HTTP only.
I will recommend using IE to test this.
Update the rule like this.
<rule name="NoSSL - folder" enabled="true" stopProcessing="true">
<match url="order.*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
</conditions>
<action type="None" />
</rule>
<rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
</rule>

Redirect from http to https results in redirect loop

I want to redirect all hostnames on my site to https.
I have added following rule in urlRewrite of IIS:
<rule name="HTTP to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}"
redirectType="Permanent" />
</rule>
But on browsing I am getting redirect loop. Am I doing something wrong?
The configuration is correct. The only issue I can see is the unclosed <rule> tag.
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>

How to remove index.php in codeigniter on Windows Server and IIS?

How to remove index.php in codeigniter on Windows Server and IIS?
I found this when i search for answer
How to rewrite the index.php of Codeigniter on Windows Azure
but when i try my CI still need index.php to run
whre the web.config file must be add and is there any other step before i edit my web.config?
If URL Rewrite module is not installed, please install it from here http://www.iis.net/downloads/microsoft/url-rewrite
Please check the complete web.config file. Place this in the same folder where the index.php is placed.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Its working in IIS in Windows server 2008 R2
This answer is a little more secure (paranoid) than the others, and is based on the way CakePHP does it. This assumes that you have a directory named "public" which contains all of the js, css, image, and font files. If you have other extensions you want to allow, add them to the second rule. You can change the directory name from "public" to anything be replacing the word "public" in rule 1 and 2.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Exclude direct access to public/*" stopProcessing="true">
<match url="^public/(.*)$" ignoreCase="false" />
<action type="None" />
</rule>
<rule name="Rewrite routed access to assets by extension" stopProcessing="true">
<match url="^(.*)(\.(css|js|otf|eot|svg|ttf|woff|woff2|jpg|png|gif|ico))$" />
<action type="Rewrite" url="public/{R:1}{R:2}" appendQueryString="false" />
</rule>
<rule name="Rewrite requested file/folder to index.php" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Make web.config put in the root directory.
User code:
<system.webServer>
<httpErrors errorMode="Detailed" />
<asp scriptErrorSentToBrowser="true"/>
<rewrite>
<rules>
<rule name="RuleRemoveIndex" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:1}" appendQueryString="true"/>
</rule>
</rules>
</rewrite>
</system.webServer>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true"/>
</system.web>
You should upload the web.config file with your project and write the code
web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="false" />
<rewrite>
<rules>
<rule name="Hide Yii Index" stopProcessing="true">
<match url="." ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile"
ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory"
ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
If You are still getting the problem then go through the following link
PHP MVC Framework IIS index.php solution

Redirect www subdomain to root domain using Intelligencia.UrlRewriter

How can I configure Intelligencia.UrlRewriter in my ASP.NET web.config file to redirect all http://www.domain.com traffic to http://domain.com?
<if header="host" match="www.yoursite.com" />
<redirect url="^(.+)$" to="http://yoursite.com$1" />
</if>
Thanks, dana, but here's what I ended up adding to my web.config file...
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.mysite.com$" />
</conditions>
<action type="Redirect" url="http://mysite.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>

Resources