Using ISAPI Rewrite to redirect domain.com to www.domain.com

My employer’s SharePoint-powered external website – which I look after – uses ISAPI Rewrite to provide “friendly” URLs for certain pages, and also to redirect old URLs to their new locations. Coming from a LAMP background, this is great for me as it basically works the same as Apache’s mod_rewrite.

Previously the website responded to requests for both domain.com and www.domain.com, which is not ideal. SEO best practice is to either redirect the non-WWW version to the WWW version, or vice-versa. In my case, www.domain.com is the preferred format, so I’m using the following rule:

### Redirect domain.com to www.domain.com
RewriteCond Host: ^domain\.com
RewriteRule (.*) http\://www\.domain\.com$1 [I,RP]

If you want to do the opposite, you’ll need this one:

### Redirect www.domain.com to domain.com
RewriteCond Host: ^www\.domain\.com
RewriteRule (.*) http\://domain\.com$1 [I,RP]
If you enjoyed this post, please share it!

    6 comments on “Using ISAPI Rewrite to redirect domain.com to www.domain.com

    1. Wayne says:

      Hi,
      This is exactly what i am looking for. Where should i place this code?
      Tks,
      Wayne.

    2. Chris Barnes says:

      Hi Wayne, once you’ve installed ISAPI_Rewrite you just need to put the code into its config file. Does that make sense?

    3. Hello Chris,

      Would it be possible for you to provide an example httpd.ini file so I can see how you have set this up. I am new to ISAPI and have no idea where to start with redirects etc. Any advice would be greatly appreciated.

    4. Chris Barnes says:

      Hi Richard,

      I don’t work on IIS any more so I’m afraid I don’t have an example httpd.ini file to hand, sorry!

    5. No worries. Thanks for the reply though. :-)

    6. Kuldeep says:

      Thanks for sharing this.
      This what we are looking for.

      Also, is it possible to redirect domain.com/para to http://www.domain.com/para?

    Comments are closed.