<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[12264] trunk: Improve IIS rewrite support.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12264">12264</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2009-11-23 18:17:46 +0000 (Mon, 23 Nov 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>Improve IIS rewrite support. Props ruslany, peaceablewhale. fixes <a href="http://trac.wordpress.org/ticket/10386">#10386</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesmiscphp">trunk/wp-admin/includes/misc.php</a></li>
<li><a href="#trunkwpadminoptionspermalinkphp">trunk/wp-admin/options-permalink.php</a></li>
<li><a href="#trunkwpincludesrewritephp">trunk/wp-includes/rewrite.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesmiscphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/misc.php (12263 => 12264)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/misc.php        2009-11-23 16:53:36 UTC (rev 12263)
+++ trunk/wp-admin/includes/misc.php        2009-11-23 18:17:46 UTC (rev 12264)
</span><span class="lines">@@ -154,7 +154,7 @@
</span><span class="cx">         // Using win_is_writable() instead of is_writable() because of a bug in Windows PHP
</span><span class="cx">         if ( ( ! file_exists($web_config_file) &amp;&amp; win_is_writable($home_path) &amp;&amp; $wp_rewrite-&gt;using_mod_rewrite_permalinks() ) || win_is_writable($web_config_file) ) {
</span><span class="cx">                 if ( iis7_supports_permalinks() ) {
</span><del>-                        $rule = $wp_rewrite-&gt;iis7_url_rewrite_rules();
</del><ins>+                        $rule = $wp_rewrite-&gt;iis7_url_rewrite_rules(false, '', '');
</ins><span class="cx">                         if ( ! empty($rule) ) {
</span><span class="cx">                                 return iis7_add_rewrite_rule($web_config_file, $rule);
</span><span class="cx">                         } else {
</span><span class="lines">@@ -587,6 +587,7 @@
</span><span class="cx">         $rule_fragment-&gt;appendXML($rewrite_rule);
</span><span class="cx">         $rules_node-&gt;appendChild($rule_fragment);
</span><span class="cx"> 
</span><ins>+        $doc-&gt;encoding = &quot;UTF-8&quot;;
</ins><span class="cx">         $doc-&gt;formatOutput = true;
</span><span class="cx">         saveDomDocument($doc, $filename);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpadminoptionspermalinkphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/options-permalink.php (12263 => 12264)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/options-permalink.php        2009-11-23 16:53:36 UTC (rev 12263)
+++ trunk/wp-admin/options-permalink.php        2009-11-23 18:17:46 UTC (rev 12264)
</span><span class="lines">@@ -225,13 +225,22 @@
</span><span class="cx"> &lt;/p&gt;
</span><span class="cx">   &lt;/form&gt;
</span><span class="cx"> &lt;?php if ($iis7_permalinks) :
</span><del>-        if ( isset($_POST['submit']) &amp;&amp; $permalink_structure &amp;&amp; ! $usingpi &amp;&amp; ! $writable ) : ?&gt;
</del><ins>+        if ( isset($_POST['submit']) &amp;&amp; $permalink_structure &amp;&amp; ! $usingpi &amp;&amp; ! $writable ) : 
+                if ( file_exists($home_path . 'web.config') ) : ?&gt;
</ins><span class="cx"> &lt;p&gt;&lt;?php _e('If your &lt;code&gt;web.config&lt;/code&gt; file were &lt;a href=&quot;http://codex.wordpress.org/Changing_File_Permissions&quot;&gt;writable&lt;/a&gt;, we could do this automatically, but it isn&amp;#8217;t so this is the url rewrite rule you should have in your &lt;code&gt;web.config&lt;/code&gt; file. Click in the field and press &lt;kbd&gt;CTRL + a&lt;/kbd&gt; to select all. Then insert this rule inside of the &lt;code&gt;/&amp;lt;configuration&amp;gt;/&amp;lt;system.webServer&amp;gt;/&amp;lt;rewrite&amp;gt;/&amp;lt;rules&amp;gt;&lt;/code&gt; element in &lt;code&gt;web.config&lt;/code&gt; file.') ?&gt;&lt;/p&gt;
</span><span class="cx"> &lt;form action=&quot;options-permalink.php&quot; method=&quot;post&quot;&gt;
</span><span class="cx"> &lt;?php wp_nonce_field('update-permalink') ?&gt;
</span><del>-        &lt;p&gt;&lt;textarea rows=&quot;10&quot; class=&quot;large-text readonly&quot; name=&quot;rules&quot; id=&quot;rules&quot; readonly=&quot;readonly&quot;&gt;&lt;?php echo esc_html($wp_rewrite-&gt;iis7_url_rewrite_rules()); ?&gt;&lt;/textarea&gt;&lt;/p&gt;
</del><ins>+        &lt;p&gt;&lt;textarea rows=&quot;9&quot; class=&quot;large-text readonly&quot; name=&quot;rules&quot; id=&quot;rules&quot; readonly=&quot;readonly&quot;&gt;&lt;?php echo esc_html($wp_rewrite-&gt;iis7_url_rewrite_rules()); ?&gt;&lt;/textarea&gt;&lt;/p&gt;
</ins><span class="cx"> &lt;/form&gt;
</span><span class="cx"> &lt;p&gt;&lt;?php _e('If you temporarily make your &lt;code&gt;web.config&lt;/code&gt; file writable for us to generate rewrite rules automatically, do not forget to revert the permissions after rule has been saved.')  ?&gt;&lt;/p&gt;
</span><ins>+                &lt;?php else : ?&gt;
+&lt;p&gt;&lt;?php _e('If the root directory of your site were &lt;a href=&quot;http://codex.wordpress.org/Changing_File_Permissions&quot;&gt;writable&lt;/a&gt;, we could do this automatically, but it isn&amp;#8217;t so this is the url rewrite rule you should have in your &lt;code&gt;web.config&lt;/code&gt; file. Create a new file, called &lt;code&gt;web.config&lt;/code&gt; in the root directory of your site. Click in the field and press &lt;kbd&gt;CTRL + a&lt;/kbd&gt; to select all. Then insert this code into the &lt;code&gt;web.config&lt;/code&gt; file.') ?&gt;&lt;/p&gt;
+&lt;form action=&quot;options-permalink.php&quot; method=&quot;post&quot;&gt;
+&lt;?php wp_nonce_field('update-permalink') ?&gt;
+        &lt;p&gt;&lt;textarea rows=&quot;18&quot; class=&quot;large-text readonly&quot; name=&quot;rules&quot; id=&quot;rules&quot; readonly=&quot;readonly&quot;&gt;&lt;?php echo esc_html($wp_rewrite-&gt;iis7_url_rewrite_rules(true)); ?&gt;&lt;/textarea&gt;&lt;/p&gt;
+&lt;/form&gt;
+&lt;p&gt;&lt;?php _e('If you temporarily make your site&amp;#8217;s root directory writable for us to generate the &lt;code&gt;web.config&lt;/code&gt; file automatically, do not forget to revert the permissions after the file has been created.')  ?&gt;&lt;/p&gt;                        
+                &lt;?php endif; ?&gt;
</ins><span class="cx">         &lt;?php endif; ?&gt;
</span><span class="cx"> &lt;?php else :
</span><span class="cx">         if ( $permalink_structure &amp;&amp; ! $usingpi &amp;&amp; ! $writable ) : ?&gt;
</span></span></pre></div>
<a id="trunkwpincludesrewritephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/rewrite.php (12263 => 12264)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/rewrite.php        2009-11-23 16:53:36 UTC (rev 12263)
+++ trunk/wp-includes/rewrite.php        2009-11-23 18:17:46 UTC (rev 12264)
</span><span class="lines">@@ -1717,19 +1717,37 @@
</span><span class="cx">          *
</span><span class="cx">          * @return string
</span><span class="cx">          */
</span><del>-        function iis7_url_rewrite_rules(){
</del><ins>+        function iis7_url_rewrite_rules($add_parent_tags = false, $indent = &quot;  &quot;, $end_of_line = &quot;\n&quot;) {
</ins><span class="cx"> 
</span><span class="cx">                 if ( ! $this-&gt;using_permalinks()) {
</span><span class="cx">                         return '';
</span><span class="cx">                 }
</span><del>-                $rules  = &quot;&lt;rule name=\&quot;wordpress\&quot; patternSyntax=\&quot;Wildcard\&quot;&gt;\n&quot;;
-                $rules .= &quot;        &lt;match url=\&quot;*\&quot; /&gt;\n&quot;;
-                $rules .= &quot;        &lt;conditions&gt;\n&quot;;
-                $rules .= &quot;                &lt;add input=\&quot;{REQUEST_FILENAME}\&quot; matchType=\&quot;IsFile\&quot; negate=\&quot;true\&quot; /&gt;\n&quot;;
-                $rules .= &quot;                &lt;add input=\&quot;{REQUEST_FILENAME}\&quot; matchType=\&quot;IsDirectory\&quot; negate=\&quot;true\&quot; /&gt;\n&quot;;
-                $rules .= &quot;        &lt;/conditions&gt;\n&quot;;
-                $rules .= &quot;        &lt;action type=\&quot;Rewrite\&quot; url=\&quot;index.php\&quot; /&gt;\n&quot;;
-                $rules .= &quot;&lt;/rule&gt;&quot;;
</del><ins>+                
+                $rules = '';
+                $extra_indent = '';
+                if ( $add_parent_tags ) {
+                        $rules .= &quot;&lt;configuration&gt;&quot;.$end_of_line;
+                        $rules .= $indent.&quot;&lt;system.webServer&gt;&quot;.$end_of_line;
+                        $rules .= $indent.$indent.&quot;&lt;rewrite&gt;&quot;.$end_of_line;
+                        $rules .= $indent.$indent.$indent.&quot;&lt;rules&gt;&quot;.$end_of_line;
+                        $extra_indent = $indent.$indent.$indent.$indent;
+                }
+                
+                $rules .= $extra_indent.&quot;&lt;rule name=\&quot;wordpress\&quot; patternSyntax=\&quot;Wildcard\&quot;&gt;&quot;.$end_of_line;
+                $rules .= $extra_indent.$indent.&quot;&lt;match url=\&quot;*\&quot; /&gt;&quot;.$end_of_line;
+                $rules .= $extra_indent.$indent.$indent.&quot;&lt;conditions&gt;&quot;.$end_of_line;
+                $rules .= $extra_indent.$indent.$indent.$indent.&quot;&lt;add input=\&quot;{REQUEST_FILENAME}\&quot; matchType=\&quot;IsFile\&quot; negate=\&quot;true\&quot; /&gt;&quot;.$end_of_line;
+                $rules .= $extra_indent.$indent.$indent.$indent.&quot;&lt;add input=\&quot;{REQUEST_FILENAME}\&quot; matchType=\&quot;IsDirectory\&quot; negate=\&quot;true\&quot; /&gt;&quot;.$end_of_line;
+                $rules .= $extra_indent.$indent.$indent.&quot;&lt;/conditions&gt;&quot;.$end_of_line;
+                $rules .= $extra_indent.$indent.&quot;&lt;action type=\&quot;Rewrite\&quot; url=\&quot;index.php\&quot; /&gt;&quot;.$end_of_line;
+                $rules .= $extra_indent.&quot;&lt;/rule&gt;&quot;;
+                
+                if ( $add_parent_tags ) {
+                        $rules .= $end_of_line.$indent.$indent.$indent.&quot;&lt;/rules&gt;&quot;.$end_of_line;
+                        $rules .= $indent.$indent.&quot;&lt;/rewrite&gt;&quot;.$end_of_line;
+                        $rules .= $indent.&quot;&lt;/system.webServer&gt;&quot;.$end_of_line;
+                        $rules .= &quot;&lt;/configuration&gt;&quot;;
+                }
</ins><span class="cx"> 
</span><span class="cx">                 $rules = apply_filters('iis7_url_rewrite_rules', $rules);
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>