download speed is very important. CDN (Content Delivery System) is good for this purpose, but up to a certain level, and good CDN providers are a bit pricey.

The good news is that some of the most important speed optimizations can be done with simple .htaccess tricks. They can make any site faster by compressing content and enabling browser caching, following Yahoo! and won’t cost you a dime.

Step 1. Gzip file compression

Compression reduces response time by reducing the size of the http response.

It’s worth compressing your HTML documents, scripts, and stylesheets with gzip. Moreover, it is worth compressing any text response, including XML and JSON.

Images and PDF files do not need to be compressed with gzip as they are already compressed. Attempting to do so will only waste CPU and may even increase the file size.

Compressing files will also save some bandwidth.

With .htaccess

For servers with Apache

mod_pagespeed is an Apache module developed by Google, it can be used like other modules.

Right now only GoDaddy and DreamHost support the mod_pagespeed module, so if you’re hosting with them, just copy and paste the following code into your .htaccess file:

<IfModule pagespeed_module>

    ModPagespeed on

    # using commands,filters etc


Many of you are hosted by other hosting providers that do not support the mod_pagespeed module.

You can use the mod_deflate module (Apache 1.3x used mod_gzip, but since Apache 2x mod_deflate is used).

<ifModule mod_deflate.c>

    AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript


With header.php

If your server does not support mod_deflate or mod_gzip, you can use this PHP script for gzip compression, it works on both Apache and Nginx.

Just copy this to your theme’s header.php file:


if ( substr_count( $_SERVER[‘HTTP_ACCEPT_ENCODING’], ‘gzip’ ) ) {



else {




Below is a graph that shows my website loading speed with and without gzip compression.

How To Speed ​​Up WordPress With Header.php And .htaccess

Step 2Disable ETags

ETags (Entity Tags) is a mechanism that web servers and browsers use to determine if a component in the browser cache matches the original one. ETags have been added as a mechanism for checking if objects are up to date.

This method is more flexible than checking by last modified date. ETag is a string that identifies a particular version of a component. The only restriction is that the string must be quoted. The backend determines the component’s ETag using the ETag header.

To disable ETags put this in your .htaccess file:

Header unset ETag

FileETag None

Using browser caching

With caching, we give the browser full instructions on how to work with certain files for a certain period of time. When the file is needed again, the browser retrieves it from its local cache instead of requesting it from the server again.

Running a site without caching makes as much sense as driving to the store with a glass of water every time you get thirsty. Not only impractical and short-sighted, but also requires a lot of effort!

Browser caching is really handy in order to get users who come back, meaning it can create loyal repeat visitors which will also save a lot of traffic.

A visitor visiting your page for the first time will make several http requests in order to download your site’s files, but by using the Expires and Cache-Control headers, you’ll make those files cacheable. This will help avoid unnecessary http requests on subsequent page views.

For servers with Apache

Apache uses mod_expires and mod_headers modules.

The mod_expires module controls the settings for the HTTP Expires header and expiration directive for the Cache-Control http header in server responses. To change other Cache-Control directives, you can use the mod_headers module.

The mod_headers module describes directives for controlling and changing the HTTP header of requests and responses. Headings can be combined, replaced or removed.

Add these rules to .htaccess to set Expires headers: Reducing MySQL Database Size

Starting with WordPress 2.6, WordPress automatically saves posts at the time of writing, they remain in the MySQL database as document versions even after the post is saved. A large database also increases website load times. I suggest to refuse saving of versions.

Paste the following code into wp-config.php to disable versioning:


define(‘WP_POST_REVISIONS’, false );

If you choose to keep this option, you can also keep versions in the database for a fixed number of days, such as 10 days.

And one more thing…

Adding an expires header won’t affect how fast the site loads on the first visit, but you’ll be surprised how much faster the loading time will be for the next page view or returning user visit.

Track how your site works: show the number of requests and processing time.

Just paste the following code after the copyright text in your theme’s footer.php file:


<?php echo get_num_queries(); ?> queries in <?php timer_stop(1); ?> seconds.

How to move a WordPress site from a subdirectory to the root directory

Let’s say your WordPress site is currently in a subdirectory instead of the site’s root directory. Such situations happen, and every time there are reasons for that. In this case, the site will have the address, and you will probably want to change it to in the future. In order not to do a lot of extra manual work, you can make a few changes to the settings and edit a couple of files. It won’t take more than five minutes of your time. And in this quick guide, you’ll learn how.

FTP client or cPanel access

Code editor

This method will work for a standard WordPress installation and with many frameworks, as well as using a parent and child theme.

But be aware! You should not use this method for multisites, as they should already be in the default root directory.

Before you start, just in case, back up your information. Use any familiar backup plugin for this. And if you haven’t got one yet, be sure to do so.