Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在wordpress中动态写入.htaccess?_.htaccess_Mod Rewrite_Wordpress Theming_Wordpress - Fatal编程技术网

如何在wordpress中动态写入.htaccess?

如何在wordpress中动态写入.htaccess?,.htaccess,mod-rewrite,wordpress-theming,wordpress,.htaccess,Mod Rewrite,Wordpress Theming,Wordpress,我正在尝试设置主题激活的永久链接结构。主题的function.php中包含以下函数 // Executes function on theme activation function myactivationfunction() { global $wp_rewrite; $wp_rewrite->set_permalink_structure( '/%category%/%postname%/' ); // register taxonomies/post ty

我正在尝试设置主题激活的永久链接结构。主题的function.php中包含以下函数

// 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);
此代码工作正常,但未将值写入.htaccess或.htaccess中,也未创建。如何动态写入.htaccess文件

任何帮助都将不胜感激


谢谢

刷新必须在
admin_init
上运行,您可以在主题开关回调中调用它,因此它只运行一次:

add_action( 'after_switch_theme', 'activate_so_19333403' );

function activate_so_19333403() {
    add_action( 'admin_init', 'flush_rewrites_so_19333403' );
}

function flush_rewrites_so_19333403() {
    global $wp_rewrite;
    $wp_rewrite->set_permalink_structure( '/%category%/%postname%/' );
    flush_rewrite_rules();  
}

检查web服务器的权限user@gwillie一切都很好。在localhost中也检查了这一点。但不工作。@gwillie当我通过单击permalink设置中的“更新”按钮更新permalink时,htaccess创建和站点正在运行<代码>刷新\重写\规则()未创建.htaccess文件。如何解决这个问题?谢谢你的回复。它不起作用。我认为
add_action('admin_init','flush_rewrites_so_19333403')在切换主题操作后不工作。当我直接打电话给它时,它工作了。我怎样才能让它工作?