wordpress插件开发添加到htaccess文件中

时间:2017-07-28 03:09:03

标签: wordpress .htaccess

我在wordpress中开发插件需要添加htaccess代码我使用insert_with_markers它写入htaccess但是它将它添加到htaccess文件的底部我需要在顶部添加代码所有的htaccess文件。我该怎么做?

1 个答案:

答案 0 :(得分:0)

您必须预先要添加到现有规则的htaccess规则。类似于:

function my_htaccess_contents( $rules )
{
    $my_content = <<<EOD
    \n # BEGIN My Added Content
    # Protect wpconfig.php
    <Files wp-config.php>
      Order Allow,Deny
      Deny from all
     </Files>
# END My Added Content\n
EOD;
return $my_content . $rules;
}
add_filter('mod_rewrite_rules', 'my_htaccess_contents');