<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MRVirtual &#187; ISA Server</title>
	<atom:link href="http://mrvirtual.de/category/isa-server/feed/" rel="self" type="application/rss+xml" />
	<link>http://mrvirtual.de</link>
	<description>Blogging about Microsoft Software</description>
	<lastBuildDate>Fri, 03 Jul 2009 23:40:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>URL Rewrite through ISA Server ends in a loop</title>
		<link>http://mrvirtual.de/2009/07/04/url-rewrite-through-isa-server-ends-in-a-loop/</link>
		<comments>http://mrvirtual.de/2009/07/04/url-rewrite-through-isa-server-ends-in-a-loop/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 23:33:09 +0000</pubDate>
		<dc:creator>MRVirtual</dc:creator>
				<category><![CDATA[IIS 7.0]]></category>
		<category><![CDATA[ISA Server]]></category>
		<category><![CDATA[URL Rewrite]]></category>

		<guid isPermaLink="false">http://mrvirtual.de/?p=20</guid>
		<description><![CDATA[Recently I’ve been having some trouble with the IIS 7 URL Rewrite module in combination with ISA Server 2006 which took me a serious amount of time to figure out the root of the behavior.
The task was pretty simple: I set up a website in IIS 7 with multiple bindings: example.net:80 and www.example.net:80. For SEO [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">Recently I’ve been having some trouble with the IIS 7 URL Rewrite module in combination with ISA Server 2006 which took me a serious amount of time to figure out the root of the behavior.</p>
<p style="text-align: left;">The task was pretty simple: I set up a website in IIS 7 with multiple bindings: example.net:80 and www.example.net:80. For SEO reasons the user shall always be redirected to example.net/… regardless of the URL he entered in the first place. This can easily be done with the following URL-Rewrite rule:<br />
<code><br />
&lt;rewrite&gt;<br />
&lt;rules&gt;<br />
&lt;rule name="Enforce Hostname" stopProcessing="true"&gt;<br />
&lt;match url="(.*)" /&gt;<br />
&lt;conditions&gt;<br />
&lt;add input="{HTTP_HOST}" negate="true" pattern="^example\.net$" /&gt;<br />
&lt;/conditions&gt;<br />
&lt;action type="Redirect" url="http://example.net/{R:0}" redirectType="Permanent" /&gt;<br />
&lt;/rule&gt;<br />
&lt;/rules&gt;<br />
&lt;/rewrite&gt;<br />
</code></p>
<p style="text-align: left;">This rule works without problems if the client can access the web server directly. However, if the site is published through ISA server I wasn’t able to get it working. The relevant portion of the publishing rule can be seen below</p>
<p style="text-align: left;">
<div id="attachment_29" class="wp-caption aligncenter" style="width: 414px"><img class="size-full wp-image-29" title="Web Site Publishing Rule Properties" src="http://mrvirtual.de/wp-content/uploads/2009/07/WebPublishing_properties.PNG" alt="Web Site Publishing Rule Properties" width="404" height="484" /><p class="wp-caption-text">Web Site Publishing Rule Properties</p></div>
<p style="text-align: left;">The public names were set to example.net; www.example.net.</p>
<p style="text-align: left;">If an external client tried to browse the website via http://example.net/site.html everything worked fine. However, if the user typed http://www.example.net/site.html he got stuck in a loop redirecting exactly to the site he came from instead of being redirected to http://example.net/site.html.</p>
<p style="text-align: left;">A Netmon trace on the client confirmed this behavior. It received an HTTP response with a response header<br />
StatusCode: 301<br />
Location: http://www.example.net/site.html</p>
<p style="text-align: left;">Furthermore the payload of the response contained a link to http://www.example.net/site.html</p>
<p style="text-align: left;">By disabling link translation in the settings of the web site publishing rule, the contents of the payload represented the URL rewrite rule correctly, but still the relevant part in the response header wasn’t like expected.<br />
To investigate this further, I installed a great free tool called <a title="CollectiveSoftware TrafficLog" href="http://www.collectivesoftware.com/Products/TrafficLog" target="_blank">TrafficLog</a>. Using TrafficLog I could see how the client requested the website (Raw Request Header) and how the ISA server altered the request (Processed Request Header) before sending it to the internal web server:</p>
<p style="text-align: left;"><code><br />
Raw Request Header (1)<br />
GET /site.html HTTP/1.1<br />
Via: 1.1 ISATOP01<br />
If-None-Match: "94802358f0fbc91:0"<br />
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)<br />
Host: www.example.net<br />
If-Modified-Since: Fri, 03 Jul 2009 15:10:04 GMT<br />
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*<br />
Accept-Language: de<br />
UA-CPU: x86<br />
Connection: Keep-Alive</code><br />
<code><br />
Processed Request Header (1)<br />
GET /site.html HTTP/1.1<br />
Via: 1.1 ISATOP01, 1.1 ISAEX<br />
Host: www.example.net<br />
If-None-Match: "94802358f0fbc91:0"<br />
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)<br />
If-Modified-Since: Fri, 03 Jul 2009 15:10:04 GMT<br />
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*<br />
Accept-Language: de<br />
UA-CPU: x86<br />
Connection: Keep-Alive<br />
</code></p>
<p style="text-align: left;">This resulted in the following response from the IIS web server, which is exactly what you expect as a result of the URL rewrite rule above:</p>
<p style="text-align: left;"><code><br />
Raw Response Header (1)<br />
HTTP/1.1 301 Moved Permanently<br />
Content-Type: text/html; charset=UTF-8<br />
Location: <span style="color: #008000;">http://example.net/site.html</span><br />
Server: Microsoft-IIS/7.0<br />
X-Powered-By: ASP.NET<br />
Date: Fri, 03 Jul 2009 19:18:34 GMT<br />
Content-Length: 155<br />
</code><br />
<code><br />
Raw Response Body bytes (1)<br />
&lt;head&gt;&lt;title&gt;Document Moved&lt;/title&gt;&lt;/head&gt;<br />
&lt;body&gt;&lt;h1&gt;Object Moved&lt;/h1&gt;This document may be found &lt;a HREF="<span style="color: #008000;">http://example.net/site.html</span>"&gt;here&lt;/a&gt;&lt;/body&gt;<br />
</code></p>
<p style="text-align: left;">But now the ISA Server does it&#8217;s part of messing up the situation. If link translation is enabled, the client will receive the following answer by ISA:</p>
<p style="text-align: left;"><code><br />
Processed Response Header (1)<br />
HTTP/1.1 301 Moved Permanently<br />
Connection: Keep-Alive<br />
Content-Length: 155<br />
Date: Fri, 03 Jul 2009 19:18:34 GMT<br />
Location: http://<span style="color: #ff0000;">www.</span>example.net/site.html<br />
Content-Type: text/html; charset=UTF-8<br />
Server: Microsoft-IIS/7.0<br />
X-Powered-By: ASP.NET<br />
</code><br />
<code><br />
Processed Response Body bytes (1)<br />
&lt;head&gt;&lt;title&gt;Document Moved&lt;/title&gt;&lt;/head&gt;<br />
&lt;body&gt;&lt;h1&gt;Object Moved&lt;/h1&gt;This document may be found &lt;a HREF="http://<span style="color: #ff0000;">www.</span>example.net/site.html"&gt;here&lt;/a&gt;&lt;/body&gt;<br />
</code></p>
<p style="text-align: left;">As described earlier, after disabling link translation in the properties of the Web Site Publishing Rule, the body of the response was correct, but the response header still contained the &#8216;www&#8217;.</p>
<p style="text-align: left;">Somehow the ISA Server still applied link translation to the response header. My next step was to completely disable the link translation Web-Filter. To do so, navigate to Configuration -&gt; Add-Ins in the ISA Management Console, choose Web Filters and disable the Link Translation Filter. At this point the web site could be access for the first time like expected. The Processed Header now looked like</p>
<p style="text-align: left;"><code><br />
Processed Response Header (1)<br />
HTTP/1.1 301 Moved Permanently<br />
Connection: Keep-Alive<br />
Content-Length: 155<br />
Date: Fri, 03 Jul 2009 20:10:51 GMT<br />
Location: <span style="color: #008000;">http://example.net/site.html</span><br />
Content-Type: text/html; charset=UTF-8<br />
Server: Microsoft-IIS/7.0<br />
X-Powered-By: ASP.NET<br />
</code><br />
<code><br />
Processed Response Body bytes (1)<br />
&lt;head&gt;&lt;title&gt;Document Moved&lt;/title&gt;&lt;/head&gt;<br />
&lt;body&gt;&lt;h1&gt;Object Moved&lt;/h1&gt;This document may be found &lt;a HREF="<span style="color: #008000;">http://example.net/site.html</span>"&gt;here&lt;/a&gt;&lt;/body&gt;<br />
</code></p>
<p style="text-align: left;">As you can imagine, it isn&#8217;t a very good idea to disable link translation server-wide because you will need this functionality in a lot of situations.</p>
<p style="text-align: left;">After a long time of trial and error I finally found the setting which caused all the trouble. Somehow it seems to be a problem if the internal site name (see screenshot above again) equals the location to which the web server redirects. In my scenario, the internal site name was set to example.net, exactly the host header enforced by the URL rewrite rule. So the simple solution to this weird  problem was to change the internal site name. You can set it to whatever you want. Since the option &#8220;Forward the original host header instead of the actual one&#8221; is selected, there is no need for a meaningful internal site name. In this case, I set it to www.example.net, but null would have been possible as well.</p>
<p style="text-align: left;">I can&#8217;t say why ISA acts the way it does in this situation. But I&#8217;m sure happy, that I could finally solve the problem. If anybody can add further information on this topic, please leave a comment!</p>
]]></content:encoded>
			<wfw:commentRss>http://mrvirtual.de/2009/07/04/url-rewrite-through-isa-server-ends-in-a-loop/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
	</channel>
</rss>
