Using insert_with_markers()
function you can insert your rules only between WordPress comments e.i. # BEGIN WordPress
and # END WordPress
.
So, you should use plain PHP to achieve your aim.
- Create your rules
- Read existing
.htaccess
and concatenate your and existing rules - Write the file
Here is a dirty example:
<?php
$str = "# BEGIN TEST\n# MY RULES\n# END TEST\n";
$str .= file_get_contents( ABSPATH . '.htaccess' );
file_put_contents( ABSPATH . '.htaccess', $str );
Or use FILE_APPEND
flag with the file_put_contents()
.
Remember!
It’s a very bad idea to allow PHP to alter your .htaccess
. One infected file is enough to break your server.