[wp-hackers] Prevent Writing to .htaccess

Eric Mann eric at eamann.com
Thu Aug 5 03:45:20 UTC 2010


One possibility (a very hacky possibility) would be to spoof the return
value of got_mod_rewrite().  This function is used as a Boolean flag before
the .htaccess file is written.  If it's True (if Apache has mod_rewrite
enabled) then the .htaccess file is written.  If it's False, then it's not.

The beauty is that there's a filter applied in the function.  So this filter
would basically disable .htaccess from being overwritten.

function disable_flush($got_rewrite) {
	return false;
}
add_filter('got_rewrite', 'disable_flush');

Though since I haven't poked around too deeply into this, I'm not sure if
this will impact anything else (i.e. actual permalink behavior) ... so I
make no guarantees :-)

~Eric

-----Original Message-----
From: wp-hackers-bounces at lists.automattic.com
[mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of John Sessford
Sent: Wednesday, August 04, 2010 8:20 PM
To: wp-hackers at lists.automattic.com
Subject: [wp-hackers] Prevent Writing to .htaccess

Hi,

I've encountered a road-block with .htaccess / Rewrite Rules. Hoping someone
here can assist.

Two issues:

1. .htaccess is flushed whenever '/wp-admin/options-permalink.php' is
loaded. It strikes me as strange that this would execute prior to action
from the user.

2. I require a method to prevent .htaccess from being flushed even when
"Save Changes" is clicked. I don't see a viable hook anywhere that can
control whether or not to write .htaccess. In my case the Rewrite Rules
should still be written to the database though. Making .htaccess read-only
is one method, but one can't always rely on users to do this.

Thoughts?

Thanks in advance,
John Sessford
_______________________________________________
wp-hackers mailing list
wp-hackers at lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list