How to add custom rewrite rule to .htaccess?

I found the solution on the Codex just after posting on the site and this is the code I was looking for:

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');

Leave a Comment