Rewrite rules in .htaccess get overwritten?

The part between the # BEGIN WordPress and # END WordPress will always be rewritten when the permalinks are flushed. You can either place your extra rewrite rules before this segment, or you can add register them in WordPress as external rewrite rules. If you flush your rules now (by visiting the Permalinks page, for example), your extra rules will be added to the .htaccess file.

add_action( 'init', 'wpse12708_init' );
function wpse12708_init()
{
    global $wp_rewrite;
    $wp_rewrite->add_external_rule( 'mobile/([^/]+)$', 'mobile/index.php?action=$1' );
    $wp_rewrite->add_external_rule( 'certificates/30-Days-Certificate-([0-9]+)$', 'pdf/index.php?type=30day&period=$1' );
    $wp_rewrite->add_external_rule( 'certificates/12-Month-Certificate$', 'pdf/index.php?type=12Month' );
}

Leave a Comment