iis7_save_url_rewrite_rules() WordPress Function

The iis7_save_url_rewrite_rules() function is used to save the URL rewrite rules for an IIS 7 server. This function is useful for making sure that the rewrite rules are saved properly when migrating a WordPress site to a new server.

iis7_save_url_rewrite_rules() #

Updates the IIS web.config file with the current rules if it is writable.


Description

If the permalinks do not require rewrite rules then the rules are deleted from the web.config file.


Top ↑

Return

(bool|null) True on write success, false on failure. Null in multisite.


Top ↑

Source

File: wp-admin/includes/misc.php

function iis7_save_url_rewrite_rules() {
	global $wp_rewrite;

	if ( is_multisite() ) {
		return;
	}

	// Ensure get_home_path() is declared.
	require_once ABSPATH . 'wp-admin/includes/file.php';

	$home_path       = get_home_path();
	$web_config_file = $home_path . 'web.config';

	// Using win_is_writable() instead of is_writable() because of a bug in Windows PHP.
	if ( iis7_supports_permalinks()
		&& ( ! file_exists( $web_config_file ) && win_is_writable( $home_path ) && $wp_rewrite->using_mod_rewrite_permalinks()
			|| win_is_writable( $web_config_file ) )
	) {
		$rule = $wp_rewrite->iis7_url_rewrite_rules( false );

		if ( ! empty( $rule ) ) {
			return iis7_add_rewrite_rule( $web_config_file, $rule );
		} else {
			return iis7_delete_rewrite_rule( $web_config_file );
		}
	}

	return false;
}


Top ↑

Changelog

Changelog
VersionDescription
2.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.