Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Azure: redirect website from www to non-www

I have this web.config file on my server.

<rewrite>
   <rules>

      <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>

      <rule name="Rule" 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" />
            <add input="{URL}" pattern="^/favicon.ico$" ignoreCase="false" negate="true" />
         </conditions>
         <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />
      </rule>

   </rules>
</rewrite>

I want to redirect URL from www to non-www. For example, if user types www.exmaple.com, it should go to https://example.com

How can I edit such a thing in above code. Thanks.

like image 563
Ronak Patel Avatar asked Jan 08 '23 11:01

Ronak Patel


1 Answers

You can have it this way (i've merge https/non-www rules in one rule)

<rule name="HTTPS and non-WWW only" stopProcessing="true">
    <match url="^(.*)$" />
    <conditions logicalGrouping="MatchAny">
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
        <add input="{HTTP_HOST}" pattern="^www\." ignoreCase="true" />
    </conditions>
    <action type="Redirect" redirectType="Found" url="https://example.com/{R:1}" />
</rule>

<rule name="Generic default rule" stopProcessing="true">
    <match url="^(.*)$" />
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_URI}" pattern="^/favicon\.ico$" ignoreCase="true" negate="true" />
    </conditions>
    <action type="Rewrite" url="/index.php/{R:1}" appendQueryString="true" />
</rule>
like image 74
Justin Iurman Avatar answered Jan 15 '23 19:01

Justin Iurman