Problem, Question

When I try to configure rewrite rules in IIS with dispatcher installed I get 500 errors.  How do I set up IIS7's URL Rewrite module so that it works with the CQ Dispatcher?

Resolution, Answer

Set up IIS 7.x

To install IIS7.x instructions here:
http://learn.iis.net/page.aspx/29/installing-iis-7-on-windows-server-2008-or-windows-server-2008-r2/

When installing IIS, make sure to enable all features.

Set up IIS URL Rewrite

You will need the IIS URL Rewrite module.  To install it, click the install button on the right side of this web page:
http://www.iis.net/download/urlrewrite

Set up Dispatcher

To install the dispatcher in IIS7, follow the instructions here:
http://dev.day.com/docs/en/cq/current/deploying/dispatcher.html#Microsoft%20Information%20Server

Configure URL Rewrite so it works with gzip compression

In this step we will configure the IIS gzip compression feature so that it works with URL output rewriting (with a default configuration these two features conflict).

  1. Go to "Start" -> "Administrative Tools" -> "Internet Information Services (IIS) Manager"
  2. In the IIS manager, browse down the tree and select the IIS site where you have configured the dispatcher.
  3. Double click "Compression"
  4. Uncheck "Enable static content compression"
  5. Go to Start and click
  6. In the "Search programs and files" edit box, enter "cmd" and hit Ctrl+Shift+Enter (this will run the command as Administrator)
  7. In the Administrative command prompt enter the following to add the LogRewrittenUrlEnabled registry entry:
    reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp\Rewrite /v LogRewrittenUrlEnabled /t REG_DWORD /d 0
  8. Go back to the "Internet Information Services (IIS) Manager" window and once again go to the dispatcher web site. Then double-click "Configuration Editor" and check that the dynamicCompressionBeforeCache property is set to False for the /system.webServer/urlCompression configuration element.
  9. Go back to the main site view (by clicking the site in the left hand tree)
  10. Double click "Modules"
  11. In the modules screen, on the right side click on "View Ordered List..."
  12. Move the URL Rewrite module (RewriteModule) below the Dynamic Compression module (DynamicCompressionModule)

Configure the Sample Rewriting Rules

In this step, we will configure some sample rewrite rules for the www.geometrixx.com website. These rules will rewrite .html extension urls so that they will no longer contain /content/geometrixx. For example if you go directly to a CQ5 publish instance, you can get to teh http://localhost:4503/content/geometrixx/en.html. With these rewrite rules, if you are accessing the IIS server using the dns hostname www.geometrixx.com then you could go to http://www.geometrixx.com/en.html and it would take you to /content/geometrixx/en.html.

To configure rewrite rules that will consistently work with the dispatcher module you will need to configure them at the server level. Also, it is much faster to configure these rules by modifying the IIS applicationHost.config xml file than by using the UI so these instructions will follow this method.

  1. Go to "Start"
  2. Enter the text "notepad" in the "Search progams and files" box and hit Ctrl+Shift+Enter (that will run the command as Administrator)
  3. Click "Yes" in the popup that appears asking "Do you want to allow the following program to make changes to this computer?"
  4. In notepad, go to "File" -> "Open"
  5. In the dialog copy/paste this path: c:\Windows\system32\inetsrv\config\applicationHost.config and hit Enter. Now the contents of the applicationHost.config file should be displayed in notepad.
  6. Copy / Paste the following right before the ending xml tag </system.webServer>
    <rewrite>
    <globalRules>
      <rule name="Root Context 1" enabled="true">
        <match url="^(.*)\.html(.*)" />
        <action type="Rewrite" url="/content/geometrixx/{R:1}.html{R:2}" appendQueryString="false" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^www.geometrixx.com" />
            <add input="{REQUEST_URI}" pattern="^/etc/" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/etc$" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/bin/" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/system/" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/libs/" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/libs$" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/var/" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/tmp/" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/tmp$" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/crx/" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/crx$" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/content/" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/crxde$" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/apps/" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/apps$" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/scripts/disp_iis" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/dispatcher/invalidate" negate="true" />
      </conditions>
    </rule>
    </globalRules>
      <outboundRules>
        <rule name="rewrite output" enabled="true">
          <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^/content/geometrixx/(.*)\.html(.*)$" />
          <action type="Rewrite" value="/{R:1}.html{R:2}" />
          <conditions>
          </conditions>
        </rule>
      </outboundRules>
    </rewrite>
  7. In notepad, hit Ctrl+s to save
  8. Go to "Start" -> "Administrative Tools" -> "Internet Information Services (IIS) Manager"
  9. Select / Expand the top node in the tree (the server icon)
  10. Right click the server icon and click "Stop" to stop the server.
  11. When it is stopped then go back and click "Start"
  12. Select the Server icon in the IIS Manager
  13. In the right panel, double click to "URL Rewrite"
  14. Now you should see the sample rules that we added via the xml files

Този материал е лицензиран под лиценз Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported  Публикациите в Twitter™ и Facebook не попадат под клаузите на Creative Commons.

Правни бележки   |   Правила за онлайн поверителност