How to write .htaccess dynamically?

I am trying to set permalink structure on theme activation. The following function included in function.php of theme.

// Executes function on theme activation
function myactivationfunction() {

    global $wp_rewrite;
    $wp_rewrite->set_permalink_structure( '/%category%/%postname%/' );
    // register taxonomies/post types here
    flush_rewrite_rules();

}
add_action("after_switch_theme", "myactivationfunction", 10 ,  2);

This code works correctly but value not writing into .htaccess or .htaccess not creating. How can i write .htaccess file dynamically?

Read More

Any help would be greatly appreciated.

Thanks

Related posts