Search The Hostwinds Guides Knowledge Base

Optimize Website Using .htaccess File

Share This Article

Having your website loading fast is a passion for most Hostwinds clients and we know how important this is. This guide is to help with reviewing your website and it’s load speed so that optimization can be seen and tested by you or your website developer.

We will also explore many options for you to use and common ways to Optimize your website using a .htaccess file. This is intended for shared hosting, business hosting, cPanel clients and VPS, Cloud and Dedicated Server clients who are using Apache web server.

For this guide, we will start out by using Google Chrome’s built in tools and using .htaccess for an Apache web server.

 

Create .htaccess File

The first thing to do is to create your .htaccess file. Before continuing with this guide, it is important to make a backup of your file to ensure this file can be restored in case your website does not load or you have any issues.

 

Google Chrome DevTools

#1 Visit your website and launch Google Dev Tools with F12 on Windows or also Ctrl + Shift + I on your keyboard. If you are using a Mac, you can use Cmd + Opt + I. Or, just right click on the web page and select Inspect Element to click on the Network tab

#2 Check the box in disable cache

#3 Click on Network from this same menu and reload the page. Here, the results and load time will show at the bottom of the screen

dev tools load time

Refresh the web page and take note of the load time as shown in the image above. You will also want to take note of the Time To First Byte which would be ideal to be under 200 ms.  The image below shows this as being 120 ms as an example:

time to first byte ttfb

 

Website Optimization

Utilize Caching

Compress Content Using Mod Deflate

Gzip Compression

Caching

Force Trailing Slash

Prevent Hotlinking

[notification type=”alert-success” close=”false” ]Replace yourdomainname with your actual domain name URL and hotlinksnotpermitted.jpg [/notification]

Redirect Website Visitors to a Mobile Site:

Stop SPAM On WordPress Blog

[notification type=”alert-success” close=”false” ]Replace yourdomainname with your actual domain name URL[/notification]

Redirect Feeds

[notification type=”alert-success” close=”false” ]Replace yourdomainname with your actual domain name URL[/notification]

Configure Your Website for HTML5 Videos

Log PHP Errors Into An Error Log

[notification type=”alert-success” close=”false” ]Replace yourdomainname with your actual domain name URL and ~/public_html/php_error.log with the location of your log file[/notification]

Run PHP Inside JavaScript Files

Block User IPs

[notification type=”alert-success” close=”false” ]Replace 123.45.6.7 and 0.1.2.3 with the actual IP addresses you want to block[/notification]

Prevent Directory Listing of Files

Custom Error Document

[notification type=”alert-success” close=”false” ]Replace /directory/filename.ext with the error document you would like to use and /errors/lostandfound.html with the 404 error page you would like to use to replace the default error documents[/notification]

Redirect Non WWW URL to WWW URL

[notification type=”alert-success” close=”false” ]Replace yourdomainname in three places, /olddirectory/oldfile.html with the old file name and newfile.html with the new file name[/notification]

Simple Redirect

[notification type=”alert-success” close=”false” ]Replace /olddirectory/oldfile.html and https://yourdomainname.com/newfile.html[/notification]

Redirect Website to https 

[notification type=”alert-success” close=”false” ]Replace yourdomain.tld with your actual domain name[/notification]

 

Related Resources