Adding Custom Rules to the htaccess File
When you change or save WP Rocket's settings, the htaccess file is regenerated. WP Rocket always places its rules at the very top of the file, so if you had any custom rules there, they will get pushed down, below our block of rules.
In some cases, it's necessary for a particular feature on your site to remain at the top or at the bottom of the file in order to function correctly.
We've created this helper plugin to help you add custom rules to the .htaccess file:
📥 Download (.zip): WP Rocket | Add custom htaccess rules
Developers: You can find the code for this plugin on GitHub.
Important! You must edit the helper plugin before use!
Only install this plugin if you are comfortable editing files via (S)FTP! This plugin itself works; however, in case something conflicts in your custom environment, you might need to remove this plugin manually via (S)FTP and edit your .htaccess directly.
Instructions to use this helper plugin
- Add your custom .htaccess rules replacing the lines 27 to 32 of this helper plugin
- The code that's already added from lines 27 to 32 is an example of setting the default browser cache to 0 seconds.
- You can see an example for a custom redirection below:
- When custom rules need to go before WP Rocket's block:
- comment lines 42 and 73 by prepending them with //
- and uncomment lines 41 and 72 by removing //
- When custom rules need to go after WP Rocket's block:
- comment lines 41 and 72 by prepending them with //,
- and uncomment lines 42 and 73 by removing //
Note: this is how the plugin is settled by default, you might not need to do anything in this step
If you're using the filter to add code after WP Rocket rules, here's how your .htaccess file will look: