WordPress – write to .htaccess

If you ever have a need to programmatically write to the .htaccess file, WordPress has a built-in function insert_with_markers to do just that. Calling that function will give you the added benefit of adding “BEGIN” and “END” markers which makes it easier to read.

There’s also a sibling function, extract_from_markers, that can read from .htaccess, assuming it was written to using the first function.

I don’t have a specific need for this since I don’t usually host on Apache servers, but I see it come up from time to time, and the functions aren’t obviously named, so I thought I note it.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.