Skip to main content
Inspiring
April 4, 2012
Question

ISAPI_Rewrite - Coldfusion 9.0.1 and IIS 7.5

  • April 4, 2012
  • 2 replies
  • 2436 views

I need to resolve canonical URLs :

non-www version should be redirected (301) to www (all pages)

IP address should be redirected to www.mywebsite.com

www.mywebsite.com/index.cfm should be redirected to www.mywebsite.com

I would really appreciate your help on this one as the following code (.htaccess file) redirects only non-www version to www

I'm not sure what to change/add to include all of the above rules.

RewriteEngine on

RewriteCond %{HTTPS} (on)?

RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]

RewriteCond %{REQUEST_URI} (.+)

RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]

    This topic has been closed for replies.

    2 replies

    pirula08Author
    Inspiring
    April 5, 2012

    I've just received a reply from my hosting provider, "we recommend using the isapi_rewrite but you can use iis URL Rewrite Module

    by setting up a web.config file" !  so,can you guys give me some pointers? really do not know where to start. how can I include all the rules mentioned above?

    Owainnorth
    Inspiring
    April 5, 2012

    Why would they recommend using isapi (an old technology) over URL Rewrite, which is a new technology? There's a GUI you can use through IIS, although I appreciate you can't use that on shared hosting. However, all the GUI does is creates an XML file (web.config) in your web root with the rules in.

    Use the GUI on your dev server and copy up the web.config with the rest of your files, job done.

    pirula08Author
    Inspiring
    April 5, 2012

    thanks for the advice Owain, I've already done that. here is the code :

    <?xml version="1.0" encoding="UTF-8"?>

    <configuration>

        <system.webServer>

            <rewrite>

                <rules>

                    <rule name="Redirect domain.com to www" patternSyntax="Wildcard" stopProcessing="true">

                        <match url="*" />

                        <conditions>

                            <add input="{HTTP_HOST}" pattern="domain.com" />

                        </conditions>

                        <action type="Redirect" url="http://www.domain.com/{R:0}" />

                    </rule>

                    <rule name="redirect index.cfm to www.domain.com" patternSyntax="Wildcard" stopProcessing="true">

                        <match url="index.cfm" />

                        <conditions>

                        </conditions>

                        <action type="Redirect" url="http://www.domain.com/" />

                    </rule>

                    <rule name="rediret IP address to www.domain.com" patternSyntax="Wildcard" stopProcessing="true">

                        <match url="*" />

                        <conditions>

                            <add input="{HTTP_HOST}" pattern="11.222.333.444" />

                        </conditions>

                        <action type="Redirect" url="http://www.domain.com/{R:0}" />

                    </rule>

                </rules>

            </rewrite>

        </system.webServer>

    </configuration>

    is everything ok with the code above? is there anything I should change to

    1. redirect non-www version to www

    2. redirect IP address to http://www.domain.com/

    3. redirect index.cfm to http://www.domain.com/

    Owainnorth
    Inspiring
    April 4, 2012

    Well this has nothing to do with ColdFusion or IIS, but okay.

    Don't bother using ISAPI_Rewrite. IIS7 has its own built-in rewrite engine with a GUI, use that instead.

    Sean Coyne
    Participating Frequently
    April 4, 2012

    Technically its not built in but you can grab it from here: http://www.iis.net/download/URLRewrite

    They have a rule template for exactly what you want to do.