<!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) && win_is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks() ) || win_is_writable($web_config_file) ) {
</span><span class="cx">                 if ( iis7_supports_permalinks() ) {
</span><del>-                        $rule = $wp_rewrite->iis7_url_rewrite_rules();
</del><ins>+                        $rule = $wp_rewrite->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->appendXML($rewrite_rule);
</span><span class="cx">         $rules_node->appendChild($rule_fragment);
</span><span class="cx">
</span><ins>+        $doc->encoding = "UTF-8";
</ins><span class="cx">         $doc->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"> </p>
</span><span class="cx"> </form>
</span><span class="cx"> <?php if ($iis7_permalinks) :
</span><del>-        if ( isset($_POST['submit']) && $permalink_structure && ! $usingpi && ! $writable ) : ?>
</del><ins>+        if ( isset($_POST['submit']) && $permalink_structure && ! $usingpi && ! $writable ) :
+                if ( file_exists($home_path . 'web.config') ) : ?>
</ins><span class="cx"> <p><?php _e('If your <code>web.config</code> file were <a href="http://codex.wordpress.org/Changing_File_Permissions">writable</a>, we could do this automatically, but it isn&#8217;t so this is the url rewrite rule you should have in your <code>web.config</code> file. Click in the field and press <kbd>CTRL + a</kbd> to select all. Then insert this rule inside of the <code>/&lt;configuration&gt;/&lt;system.webServer&gt;/&lt;rewrite&gt;/&lt;rules&gt;</code> element in <code>web.config</code> file.') ?></p>
</span><span class="cx"> <form action="options-permalink.php" method="post">
</span><span class="cx"> <?php wp_nonce_field('update-permalink') ?>
</span><del>-        <p><textarea rows="10" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_html($wp_rewrite->iis7_url_rewrite_rules()); ?></textarea></p>
</del><ins>+        <p><textarea rows="9" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_html($wp_rewrite->iis7_url_rewrite_rules()); ?></textarea></p>
</ins><span class="cx"> </form>
</span><span class="cx"> <p><?php _e('If you temporarily make your <code>web.config</code> file writable for us to generate rewrite rules automatically, do not forget to revert the permissions after rule has been saved.') ?></p>
</span><ins>+                <?php else : ?>
+<p><?php _e('If the root directory of your site were <a href="http://codex.wordpress.org/Changing_File_Permissions">writable</a>, we could do this automatically, but it isn&#8217;t so this is the url rewrite rule you should have in your <code>web.config</code> file. Create a new file, called <code>web.config</code> in the root directory of your site. Click in the field and press <kbd>CTRL + a</kbd> to select all. Then insert this code into the <code>web.config</code> file.') ?></p>
+<form action="options-permalink.php" method="post">
+<?php wp_nonce_field('update-permalink') ?>
+        <p><textarea rows="18" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_html($wp_rewrite->iis7_url_rewrite_rules(true)); ?></textarea></p>
+</form>
+<p><?php _e('If you temporarily make your site&#8217;s root directory writable for us to generate the <code>web.config</code> file automatically, do not forget to revert the permissions after the file has been created.') ?></p>                        
+                <?php endif; ?>
</ins><span class="cx">         <?php endif; ?>
</span><span class="cx"> <?php else :
</span><span class="cx">         if ( $permalink_structure && ! $usingpi && ! $writable ) : ?>
</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 = " ", $end_of_line = "\n") {
</ins><span class="cx">
</span><span class="cx">                 if ( ! $this->using_permalinks()) {
</span><span class="cx">                         return '';
</span><span class="cx">                 }
</span><del>-                $rules = "<rule name=\"wordpress\" patternSyntax=\"Wildcard\">\n";
-                $rules .= "        <match url=\"*\" />\n";
-                $rules .= "        <conditions>\n";
-                $rules .= "                <add input=\"{REQUEST_FILENAME}\" matchType=\"IsFile\" negate=\"true\" />\n";
-                $rules .= "                <add input=\"{REQUEST_FILENAME}\" matchType=\"IsDirectory\" negate=\"true\" />\n";
-                $rules .= "        </conditions>\n";
-                $rules .= "        <action type=\"Rewrite\" url=\"index.php\" />\n";
-                $rules .= "</rule>";
</del><ins>+                
+                $rules = '';
+                $extra_indent = '';
+                if ( $add_parent_tags ) {
+                        $rules .= "<configuration>".$end_of_line;
+                        $rules .= $indent."<system.webServer>".$end_of_line;
+                        $rules .= $indent.$indent."<rewrite>".$end_of_line;
+                        $rules .= $indent.$indent.$indent."<rules>".$end_of_line;
+                        $extra_indent = $indent.$indent.$indent.$indent;
+                }
+                
+                $rules .= $extra_indent."<rule name=\"wordpress\" patternSyntax=\"Wildcard\">".$end_of_line;
+                $rules .= $extra_indent.$indent."<match url=\"*\" />".$end_of_line;
+                $rules .= $extra_indent.$indent.$indent."<conditions>".$end_of_line;
+                $rules .= $extra_indent.$indent.$indent.$indent."<add input=\"{REQUEST_FILENAME}\" matchType=\"IsFile\" negate=\"true\" />".$end_of_line;
+                $rules .= $extra_indent.$indent.$indent.$indent."<add input=\"{REQUEST_FILENAME}\" matchType=\"IsDirectory\" negate=\"true\" />".$end_of_line;
+                $rules .= $extra_indent.$indent.$indent."</conditions>".$end_of_line;
+                $rules .= $extra_indent.$indent."<action type=\"Rewrite\" url=\"index.php\" />".$end_of_line;
+                $rules .= $extra_indent."</rule>";
+                
+                if ( $add_parent_tags ) {
+                        $rules .= $end_of_line.$indent.$indent.$indent."</rules>".$end_of_line;
+                        $rules .= $indent.$indent."</rewrite>".$end_of_line;
+                        $rules .= $indent."</system.webServer>".$end_of_line;
+                        $rules .= "</configuration>";
+                }
</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>