How can I make my .htaccess file writeable by wp-admin?

Short version: You can’t.

Long version: Technically there are ways this can be achieved but they are ① likely not available to you as a user on a shared server where you do not have root permissions and ② even if they were, they come with ‘gotchas’ that you really don’t want to deal with.

First of all, if you are not the sys-admin with root permissions it is doubtful that you have any hope of setting the necessary permissions.

  • The UNIX permission bits control whether each of you, people in your group and anybody can read, write and execute files. Given that set of options and the fact that you and the web server are likely not in the same group, there is no way for you no use those permissions to set a value whereby you and the web server user can write the file but other people cannot. By definition you would have to change the “world” permissions and … you can do the math.

    On the off chance that your user account and the web server in fact run in the same user group, you should seriously begin to doubt the security of your web service provider.

    A slightly less insane technique that some hosts employ is giving you a special interface to convert specific files and folders to be owned by the web server. This is a convenience-over-security choice they make that makes like easy for folks, but it comes with strings attached. In any event you would not be able to manually edit the file without changing the ownership back to yourself.

  • Even if one or more way is afforded you to let the webserver software edit the .htaccess file, you are much better off not taking them up on it. In a shared hosting environment you have to realize that other people besides you are ALSO executing code as the web server user. If your WordPress installation is able to change your .htaccess file, what is to stop the next guys’s wordpress from maliciously changing yours? Well theoretically PHP’s open_base_dir sittings will jail it to reading and writing things inside of your DOCUMENT_ROOT, but while the PHP module is reasonably good about enforcing this it is quite common for ISP’s and small time hosts to have other CGI systems that are not properly jailed or straight up miss-configured server settings that allow other users on the same server to mess with anything any other users have converted to be owned by the webserver.

The only technical way to really make this possible is with a virtual host setup that actually runs as you when serving your site (which actually introduces other risks) or with file system ACL’s — and while possible it is unlikely that your ISP is equipped to configure those correctly.

In summary, you are actually better off security-wise with wp-admin not being able to write to .htaccess. This should be an infrequent issue anyway, usually on version changes of either WordPress or the server software (e.g. the switch from Apache 2.2 to 2.4 meant a lot of .htaccess files across the net had to be updated, but that was years in the making). This is not something that should be changing every time you update your site, only if you made an architectural change and needed to facilitate the migration of old URL’s to new ones, etc.