Tuesday, 4 March 2014

IIS - NON WWW to WWW URL Redirection.

URL Redirection using IIS 7.0 / 7.5.
In IIS server, we have an option called URL Rewrite.

Steps to Redirect an URL:
--------------------------

  • Open IIS Manager (Internet Information Services Manager).
  • Double Click on URL Rewrite Icon.

  • Click on Add Rules link under Actions Pane on Right Side bar.
  • Select Blank Rule option from the Popup window and click on OK
  • Provide Rule Name as "Non www mysitename.com to www"
  • Select Match URL using "wildcards".
  • Expand Conditions box
    • Click on Add Condition link on right sidebar.
    • Make Condition input as {HTTP_HOST}
    • Select Input string as "Matches the Pattern"
    • pattern as mysitename.com
    • Click on OK
  • Set Action under Action Box
    • Select Action Type as "Redirect"
    • Fill Redirect URL as "http://www.mysitename.com/{R:0}" under Action Properties Section.
    • Check Append Query String Checkbox
    • Select Redirect Type as "Permanent 301"
  • Click on Apply link on Right Side bar

Using Simple Text Editor Also we can Redirect the URL:
---------------------------------------------------------------

Wildcard based redirection:

<rewrite>
    <rules>
        <rule name="Non www mysitename.com to www" patternSyntax="Wildcard" stopProcessing="true">
            <match url="*" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="mysitename.com" />
            </conditions>
            <action type="Redirect" url="http://www.mysitename.com/{R:0}" />
        </rule>
    </rules>
</rewrite>

Regular Expression based URL redirection:

<rewrite>
    <rules>
        <rule name="Non www mysitename.com to www" patternSyntax="ECMAScript" stopProcessing="true">
            <match url=".*" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^mysitename.com$" />
            </conditions>
            <action type="Redirect" url="http://www.mysitename.com/{R:0}" />
        </rule>
    </rules>
</rewrite>

No comments:

Post a Comment

Thank you so much for providing your valuable feedback. I will will look into them and update my skills & technologies accordingly.