htaccess is the main entry point for any WordPress website. When you enter an url to a WordPress website, url request is sent to the server and it is then handled by WordPress using rewrite rules defined in the htacess file.
Often, htaccess file is managed by WordPress core and caching plugins like Litespeed or W3TC. But it is a simple text file, so we can edit that too using any FTP and code editing tools.
In this post, I am sharing you my ultimage htaccess configuration suitable for busy websites with high-volume visitor traffic. For small and highly static web sites, the optimizations here may not be required.
Ultimate High Speed .htaccess Configuration
- Open your favorite FTP tool to download .htaccess file in the root of your WordPress installation directory.
Note. That file is a hidden file by default, you need to switch show hidden files option on your FTP application if it is not visible.
- Download htaccess and make sure you make a backup copy before changing the server version.
- Paste following code on top of the file, before any other rules defined in the file:
- Finally upload the file to the server.
How Does It Work?
This file improves security by adding X-XSS-Protection header, and removing PHP version from the request. It also prevents website to be displayed in an iframe.
For the performance side, it forces user’s browser to cache static resources a long time. Those resources are images which rarely change after uploading, and css and js files, which are generally static.
And finally, it removes WordPress’ handling of static resources, so your static files won’t use any PHP resources on your server.