Windows server web.config file to redirect all URLS into HTTPS

Used below code to redirect all URLs into HTTPS in windows server using web.config file.

 

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite> 
<rules>
 
 
<rule name="Force HTTPS" enabled="true" stopProcessing="true">>
<match url="(.*)" /> 
<conditions logicalGrouping="MatchAll">
<add input="{HTTPS}" pattern="off" ignoreCase="true" /> 
<add input="{REQUEST_URI}" pattern="^(.*)/ccadmin(.*)" ignoreCase="true" negate="true" /> 
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
 
 
 
<rule name="Remove index.php Rule" stopProcessing="true"> 
<match url=".*" ignoreCase="false" /> 
<conditions> 
<add input="{URL}" pattern="^/(media|skin|js)/" ignoreCase="false" negate="true" /> 
<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" /> 
</rule>
 
 
 
</rules>
</rewrite>
</system.webServer>
<system.net>
<mailSettings>
<smtp>
<network host="localhost" />
</smtp>
</mailSettings>
</system.net>
</configuration>

Only below code worked for HTTPS redirection:

<rule name="Force HTTPS" enabled="true" stopProcessing="true">>
<match url="(.*)" /> 
<conditions logicalGrouping="MatchAll">
<add input="{HTTPS}" pattern="off" ignoreCase="true" /> 
<add input="{REQUEST_URI}" pattern="^(.*)/admin(.*)" ignoreCase="true" negate="true" />  <!-- Restrict the admin URLS from HTTPS redirection -->
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>

 

 

Used below code to restrict particular URL from HTTPS redirection based on URL slug.

From the above code “MatchAll” value allow to work the HTTPS redirection once all the condition success within the <conditions> tag

logicalGrouping="MatchAll"

 

So, I have added two conditions like below within <conditions> tag.

  1. Check the loading URL is HTTPS or Not
  2. Check the loading URL slug
<add input="{HTTPS}" pattern="off" ignoreCase="true" /> 
<add input="{REQUEST_URI}" pattern="^(.*)/admin(.*)" ignoreCase="true" negate="true" />  <!-- Restrict the admin URLS from HTTPS redirection -->

 

So, above code restrict the admin URL from HTTPS redirection.

Windows server HTTP Error 500.50 – URL Rewrite Module Error while accessing the image

Hi All

We faced the problem while upload the image in windows server!

Image uploaded fine into server , but its not accessible from user-end through browser. Error displayed “500.50 – URL Rewrite Module Error

Reason:
The problem happens, when you use PHP to upload a file.  When you upload a file or image, PHP sends the file to a temporary directory on the hard drive (C:\Windows\Temp) and then copies it over to it’s intended directory(into site location).  Once the file has landed in the temporary directory, it is assigned the permissions of that directory. The problem is when Windows copies that file, it keeps the temporary directory’s permissions and doesn’t inherit your web directory’s permissions.

Solution:
1. Change the permissions on the temp folder(C:\Windows\Temp) giving IIS_IUSRS – write/modify. Find below image.

2. Change the path of the temp folder in the PHP.ini file to a folder that does have IIS_IUSRS write/modify permission.

windows temp folder permission change - 500.50 - URL Rewrite Module Error