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.xTo 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).
- Go to "Start" -> "Administrative Tools" -> "Internet Information Services (IIS) Manager"
- In the IIS manager, browse down the tree and select the IIS site where you have configured the dispatcher.
- Double click "Compression"
- Uncheck "Enable static content compression"
- Go to Start and click
- In the "Search programs and files" edit box, enter "cmd" and hit Ctrl+Shift+Enter (this will run the command as Administrator)
- 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 - 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.
- Go back to the main site view (by clicking the site in the left hand tree)
- Double click "Modules"
- In the modules screen, on the right side click on "View Ordered List..."
- 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.
- Go to "Start"
- Enter the text "notepad" in the "Search progams and files" box and hit Ctrl+Shift+Enter (that will run the command as Administrator)
- Click "Yes" in the popup that appears asking "Do you want to allow the following program to make changes to this computer?"
- In notepad, go to "File" -> "Open"
- 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.
- 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> - In notepad, hit Ctrl+s to save
- Go to "Start" -> "Administrative Tools" -> "Internet Information Services (IIS) Manager"
- Select / Expand the top node in the tree (the server icon)
- Right click the server icon and click "Stop" to stop the server.
- When it is stopped then go back and click "Start"
- Select the Server icon in the IIS Manager
- In the right panel, double click to "URL Rewrite"
- Now you should see the sample rules that we added via the xml files