From 97b5a5f483a6f0205fc6c0f9f52560352deca8b0 Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 23 Nov 2009 18:17:46 +0000 Subject: [PATCH] Improve IIS rewrite support. Props ruslany, peaceablewhale. fixes #10386 git-svn-id: http://svn.automattic.com/wordpress/trunk@12264 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/misc.php | 3 ++- wp-admin/options-permalink.php | 13 ++++++++++-- wp-includes/rewrite.php | 36 +++++++++++++++++++++++++--------- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/wp-admin/includes/misc.php b/wp-admin/includes/misc.php index 356c6b0018..96bcab3e3d 100644 --- a/wp-admin/includes/misc.php +++ b/wp-admin/includes/misc.php @@ -154,7 +154,7 @@ function iis7_save_url_rewrite_rules(){ // Using win_is_writable() instead of is_writable() because of a bug in Windows PHP if ( ( ! file_exists($web_config_file) && win_is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks() ) || win_is_writable($web_config_file) ) { if ( iis7_supports_permalinks() ) { - $rule = $wp_rewrite->iis7_url_rewrite_rules(); + $rule = $wp_rewrite->iis7_url_rewrite_rules(false, '', ''); if ( ! empty($rule) ) { return iis7_add_rewrite_rule($web_config_file, $rule); } else { @@ -587,6 +587,7 @@ function iis7_add_rewrite_rule($filename, $rewrite_rule) { $rule_fragment->appendXML($rewrite_rule); $rules_node->appendChild($rule_fragment); + $doc->encoding = "UTF-8"; $doc->formatOutput = true; saveDomDocument($doc, $filename); diff --git a/wp-admin/options-permalink.php b/wp-admin/options-permalink.php index c06fa08c8a..c4b71d55a5 100644 --- a/wp-admin/options-permalink.php +++ b/wp-admin/options-permalink.php @@ -225,13 +225,22 @@ $structures = array(

+ if ( isset($_POST['submit']) && $permalink_structure && ! $usingpi && ! $writable ) : + if ( file_exists($home_path . 'web.config') ) : ?>

web.config file were writable, we could do this automatically, but it isn’t so this is the url rewrite rule you should have in your web.config file. Click in the field and press CTRL + a to select all. Then insert this rule inside of the /<configuration>/<system.webServer>/<rewrite>/<rules> element in web.config file.') ?>

-

+

web.config file writable for us to generate rewrite rules automatically, do not forget to revert the permissions after rule has been saved.') ?>

+ +

writable, we could do this automatically, but it isn’t so this is the url rewrite rule you should have in your web.config file. Create a new file, called web.config in the root directory of your site. Click in the field and press CTRL + a to select all. Then insert this code into the web.config file.') ?>

+
+ +

+
+

web.config file automatically, do not forget to revert the permissions after the file has been created.') ?>

+ diff --git a/wp-includes/rewrite.php b/wp-includes/rewrite.php index 69c76a853f..05b8d715a2 100644 --- a/wp-includes/rewrite.php +++ b/wp-includes/rewrite.php @@ -1717,19 +1717,37 @@ class WP_Rewrite { * * @return string */ - function iis7_url_rewrite_rules(){ + function iis7_url_rewrite_rules($add_parent_tags = false, $indent = " ", $end_of_line = "\n") { if ( ! $this->using_permalinks()) { return ''; } - $rules = "\n"; - $rules .= " \n"; - $rules .= " \n"; - $rules .= " \n"; - $rules .= " \n"; - $rules .= " \n"; - $rules .= " \n"; - $rules .= ""; + + $rules = ''; + $extra_indent = ''; + if ( $add_parent_tags ) { + $rules .= "".$end_of_line; + $rules .= $indent."".$end_of_line; + $rules .= $indent.$indent."".$end_of_line; + $rules .= $indent.$indent.$indent."".$end_of_line; + $extra_indent = $indent.$indent.$indent.$indent; + } + + $rules .= $extra_indent."".$end_of_line; + $rules .= $extra_indent.$indent."".$end_of_line; + $rules .= $extra_indent.$indent.$indent."".$end_of_line; + $rules .= $extra_indent.$indent.$indent.$indent."".$end_of_line; + $rules .= $extra_indent.$indent.$indent.$indent."".$end_of_line; + $rules .= $extra_indent.$indent.$indent."".$end_of_line; + $rules .= $extra_indent.$indent."".$end_of_line; + $rules .= $extra_indent.""; + + if ( $add_parent_tags ) { + $rules .= $end_of_line.$indent.$indent.$indent."".$end_of_line; + $rules .= $indent.$indent."".$end_of_line; + $rules .= $indent."".$end_of_line; + $rules .= ""; + } $rules = apply_filters('iis7_url_rewrite_rules', $rules);