WordPress.org

Forums

All In One WP Security & Firewall
[resolved] Filtering htaccess rules (2 posts)

  1. glyndavidson
    Member
    Posted 1 year ago #

    Is it possible to give an example of how to filter the htaccess rules?

    I tried this in an MU plugin but it doesn't work :(

    add_filter('aiowps_htaccess_rules_before_writing', 'change_htaccess_rules');
    function change_htaccess_rules($rulesarray){
    	foreach($rulesarray as $rule){
    		str_replace('Options All -Indexes', 'Options -Indexes', $rule);
    	}
    	return $rulesarray;
    }

    https://wordpress.org/plugins/all-in-one-wp-security-and-firewall/

  2. wpsolutions
    Member
    Plugin Author

    Posted 1 year ago #

    Hi @glyndavidson,
    The reason your code isn't working is because you aren't modifying the original "$rulesarray".

    Here's an alternative and faster way you can try by using json_encode/decode:

    function change_htaccess_rules($rulesarray){
    return json_decode(str_replace('Options All -Indexes', 'Options -Indexes',  json_encode($rulesarray)));
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.