Using WordPress ‘iis7_delete_rewrite_rule()’ PHP function

The iis7_delete_rewrite_rule() WordPress PHP function deletes a WordPress rewrite rule from the web.config file if it exists there.

Usage

iis7_delete_rewrite_rule( $filename );

Example:

iis7_delete_rewrite_rule( 'web.config' );

Parameters

  • $filename (string) – Required. Name of the configuration file.

More information

See WordPress Developer Resources: iis7_delete_rewrite_rule()

Examples

Delete Rewrite Rule in web.config

This example demonstrates how to delete a rewrite rule in the ‘web.config’ file.

// Delete the rewrite rule from the 'web.config' file
iis7_delete_rewrite_rule( 'web.config' );

Delete Rewrite Rule in Custom Config File

This example demonstrates how to delete a rewrite rule in a custom configuration file named ‘custom.config’.

// Delete the rewrite rule from the 'custom.config' file
iis7_delete_rewrite_rule( 'custom.config' );

Delete Rewrite Rule Based on User Input

This example demonstrates how to delete a rewrite rule from a configuration file based on user input.

// Get user input
$config_file = $_POST['config_file'];

// Delete the rewrite rule from the specified file
iis7_delete_rewrite_rule( $config_file );

Check If File Exists Before Deleting Rewrite Rule

This example demonstrates how to check if a configuration file exists before attempting to delete a rewrite rule.

// Configuration file
$config_file = 'web.config';

// Check if the file exists
if ( file_exists( $config_file ) ) {
    // Delete the rewrite rule from the configuration file
    iis7_delete_rewrite_rule( $config_file );
} else {
    echo 'The configuration file does not exist.';
}

Delete Rewrite Rule and Display Confirmation Message

This example demonstrates how to delete a rewrite rule and display a confirmation message.

// Delete the rewrite rule from the 'web.config' file
iis7_delete_rewrite_rule( 'web.config' );

// Display a confirmation message
echo 'The rewrite rule has been successfully deleted.';