From 0ff4f66464f24a5322bad6a17cff4b85cc886b22 Mon Sep 17 00:00:00 2001 From: Peter Westwood Date: Wed, 18 Jul 2007 20:46:54 +0000 Subject: [PATCH] Update .htaccess file when rewrite rules are deleted if it exists. Fixes #4018 git-svn-id: https://develop.svn.wordpress.org/trunk@5809 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/includes/misc.php | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/wp-admin/includes/misc.php b/wp-admin/includes/misc.php index 46a9bc3996..b9550cb2f2 100644 --- a/wp-admin/includes/misc.php +++ b/wp-admin/includes/misc.php @@ -89,21 +89,28 @@ function insert_with_markers( $filename, $marker, $insertion ) { } } +/** + * Updates the htaccess file with the current rules if it is writable. + * + * Always writes to the file if it exists and is writable to ensure that we blank out old rules. + */ + function save_mod_rewrite_rules() { - global $is_apache, $wp_rewrite; + global $wp_rewrite; + $home_path = get_home_path(); + $htaccess_file = $home_path.'.htaccess'; - if (!$wp_rewrite->using_mod_rewrite_permalinks() ) - return false; - - if (!((!file_exists( $home_path.'.htaccess' ) && is_writable( $home_path ) ) || is_writable( $home_path.'.htaccess' ) ) ) - return false; - - if (! got_mod_rewrite() ) - return false; - - $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() ); - return insert_with_markers( $home_path.'.htaccess', 'WordPress', $rules ); + // If the file doesn't already exists check for write access to the directory and whether of not we have some rules. + // else check for write access to the file. + if ((!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks()) || is_writable($htaccess_file)) { + if ( got_mod_rewrite() ) { + $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() ); + return insert_with_markers( $htaccess_file, 'WordPress', $rules ); + } + } + + return false; } function update_recently_edited( $file ) {