Home » Web » 10 .htaccess Snippets to Improve Website’s Performance

10 .htaccess Snippets to Improve Website’s Performance

Reading Time: 3 minutes

The power of .htaccess file of a website in terms of optimizing the performance of a website often goes unnoticed. It can be utilized to speed up a website and reduce its loading time by a significant margin. You need not to be a rocket scientist in order to do that. A few simple fixes here and there can help you in meeting the purpose pretty easily. Here are 10 .htaccess snippets to improve website’s performance.

1. Purge the URL from www
It is advised that the URL must be stripped of the www part for SEO purposes. This can be done with the below mentioned .htaccess snippet that will strip the www part and redirect your site visitors to the non www URL:


2. Make URLs future proof and SEO friendly
Search engines deride sites with complex URL structure, such as those with addresses like ‘index.php?product_id=’. One should avoid creating such a site structure that is not SEO friendly. Instead, the focus must be on creating cleaner URLs that are liked by the search engines. Such URL structure is easier to manage than the former. One may add as many sub folders to the site structure as he or she may want.

Following code snippet can be used to prevent Apache from identifying files and deciding how to handle them on the basis of their extension with the following code:

<Files magic>
ForceType application/x-httpd-php5
</Files>

3. Prevent Hotlinking
Hotlinking is the process of utilization of images and other files of a site by another website. In this way, the bandwidth of the former is used illegally by the latter, thereby resulting in slowing down of its speed. Hotlinkers must be stopped in their tracks in order to prevent them from using the crucial bandwidth of a given site. Here is .htaccess code to prevent hotlinking:


4. Use rel=”canonical” tag
If your website is having pages with similar content or want to prevent web scrapers from getting undue advantage of your content, you can make use of the rel=”canonical” tag for this purpose. This will make Google and other search engines know that the particular page or document is the original one and it should not index any other page with similar content. For images and PDF documents, one can use the tag on the HTML page or the download page of the same.

Here is how to use the tag:


5. Redirect feeds from WordPress to Feedburner

Wordpress blog owners can redirect all feeds they are using on their blogs to their feedburner feeds using this code:


6. For mobile content crawling use the Vary header
In case you are altering the page HTML instead of responsive design while using the same URLs for mobile access, you can send the vary header for this purpose.

Header append Vary User-Agent

7. Force download of chosen file types
Website owners who want to force download of chosen file types instead of letting the browser decide the type of file can make use of the following code:


8. Better site speed with improved caching
Site speed has a tremendous bearing on both user experience and search engine ranks. Increase the site speed with improved caching with this code:


9. Custom 404 page
Set up a custom 404 error page to bring lost visitors back to track for improving their overall experience while visiting your site.

ErrorDocument 404 /cool404.html

# Can also do the same for other errors…
ErrorDocument 500 /cool500.html

10. Compress static data to reduce page weight
If you send compressed data to the visitors, the client at their end will decompress the data and help in reduce bandwidth usage on both ends.

(Have been liking our posts for a while? Subscribe now! We’ll make sure that you never miss an update. And talk to our Experts now if you need professional help with your Custom Web Development services)

Varun Bhagat is a technology geek and works in PixelCrayons as a Sr. Technology Consultant. He possesses in-depth knowledge of different web development technology and helps our clients to choose the best technology as per their needs.

Are you ready to turn your idea into reality? Contact Us Now

More from PixelCrayons Blog:-

5 Great Tips for an SEO Friendly Web Design

5 Great Tips for an SEO Friendly Web Design

SEO friendly web design plays an important role in making the website more popular in search engines. An SEO friendly website is one which is optimized through […] - Read More

Points To Remember While Coding A Website

Points To Remember While Coding A Website

In web, search engine plays a major role as it is being used by Internet surfers all the time. It holds importance particularly for 'consumers' to find products and […] - Read More

Website Health: 9 Checklist You Can’t Miss in 2016

Website Health: 9 Checklist You Can’t Miss in 2016

For the success of your business, it is vital to have a "healthy" website that runs at optimal power. A website with structural errors and not properly optimized will […] - Read More

Develop SEO friendly Web Design

Search Engine Friendly Website Design

Online to please your visitors and convert them into customers, you can neither possibly overlook the phenomenal significance of search engines (like Google, Yahoo, […] - Read More