9 Replies Latest reply: Apr 6, 2012 2:38 AM by pirula08 RSS

    ISAPI_Rewrite - Coldfusion 9.0.1 and IIS 7.5

    pirula08 Community Member

      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]

        • 1. Re: ISAPI_Rewrite - Coldfusion 9.0.1 and IIS 7.5
          Owain North Community Member

          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.

          • 2. Re: ISAPI_Rewrite - Coldfusion 9.0.1 and IIS 7.5
            Sean Coyne

            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.

            • 3. Re: ISAPI_Rewrite - Coldfusion 9.0.1 and IIS 7.5
              pirula08 Community Member

              not sure that I can use it due to shared hosting !

              • 4. Re: ISAPI_Rewrite - Coldfusion 9.0.1 and IIS 7.5
                Sean Coyne Community Member

                Well, yeah.  That will cramp your style.

                • 5. Re: ISAPI_Rewrite - Coldfusion 9.0.1 and IIS 7.5
                  pirula08 Community Member

                  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?

                  • 6. Re: ISAPI_Rewrite - Coldfusion 9.0.1 and IIS 7.5
                    Owain North Community Member

                    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.

                    • 7. Re: ISAPI_Rewrite - Coldfusion 9.0.1 and IIS 7.5
                      pirula08 Community Member

                      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/

                      • 8. Re: ISAPI_Rewrite - Coldfusion 9.0.1 and IIS 7.5
                        Owain North Community Member

                        Honestly I have no idea, as I said this is a ColdFusion forum not an IIS one so I can't help I'm afraid. Does it do what you expect it to?

                        • 9. Re: ISAPI_Rewrite - Coldfusion 9.0.1 and IIS 7.5
                          pirula08 Community Member

                          I spent several hours reading/learning more about IIS URL Rewrite Module and I can safely say that I'm simply amazed at how well it works! So, who on earth would use ISAPI_Rewrite ever again as both simple and more sophisticated rules can be added easily with URL Rewrite 2.0 (for advanced rules you need to be familiar with regular expressions ofcourse). Anyway, I will continue to read about this new technology and hopefully will be able to help someone if needed in the future

                           

                          "Does it do what you expect it to?" , yup, it works like a charm