Make WordPress Core


Ignore:
Timestamp:
07/18/2007 08:46:54 PM (18 years ago)
Author:
westi
Message:

Update .htaccess file when rewrite rules are deleted if it exists.
Fixes #4018

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/misc.php

    r5566 r5809  
    9090}
    9191
     92/**
     93 * Updates the htaccess file with the current rules if it is writable.
     94 *
     95 * Always writes to the file if it exists and is writable to ensure that we blank out old rules.
     96 */
     97
    9298function save_mod_rewrite_rules() {
    93     global $is_apache, $wp_rewrite;
     99    global $wp_rewrite;
     100   
    94101    $home_path = get_home_path();
     102    $htaccess_file = $home_path.'.htaccess';
    95103
    96     if (!$wp_rewrite->using_mod_rewrite_permalinks() )
    97         return false;
    98 
    99     if (!((!file_exists( $home_path.'.htaccess' ) && is_writable( $home_path ) ) || is_writable( $home_path.'.htaccess' ) ) )
    100         return false;
    101 
    102     if (! got_mod_rewrite() )
    103         return false;
    104 
    105     $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() );
    106     return insert_with_markers( $home_path.'.htaccess', 'WordPress', $rules );
     104    // If the file doesn't already exists check for write access to the directory and whether of not we have some rules.
     105    // else check for write access to the file.
     106    if ((!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks()) || is_writable($htaccess_file)) {
     107        if ( got_mod_rewrite() ) {
     108            $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() );
     109            return insert_with_markers( $htaccess_file, 'WordPress', $rules );
     110        }
     111    }
     112   
     113    return false;
    107114}
    108115
Note: See TracChangeset for help on using the changeset viewer.