A few optimizations in .htaccess

Why worth reading further and keep optimizing:

  • You can do it on Your own, practically no technical skills required (but remember to have copy of Your .htaccess file in case something goes wrong)
  • Your websites will just rank higher (and that’s the reason why You’re here, am I right?)

 

A few example of .htaccess usage:

Redirecting site versions (www, without www, index.html)

Probably Your heard about ‘duplicate content’ and that it can destroy all of your SEO work. And having site versions with ‘www’ and without it and not redirecting them properly is recognized as ‘duplicate content’.

When You weren’t responsible for this part of web development (and don’t really know what going on here) type domain.com, www.domain.com and www.domain.com/index.html in your browser (or another index file type like index.php) and see what happens. If You always see single site version, for example without ‘www’ prefix it’s just good (by the way redirecting all site versions to version without ‘www’ is better idea from SEO perspective).

If no, we have some work here.

First how to remove index.html

If You have index.php – just change index\.html to index\.php

And now – redirecting from www to to withot www version:

301 redirections

301 redirections are commonly used to ‘tell search engine’, that we have permamently moved our site to new location. 301 redirection gives almost 100% link-juice from old domain to the new one and in most instances it’s the best method for implementing redirects on a website.

When we want to redirect traffic from /category/television/ to /category/tv/ we should put code like below in our .htaccess:

Caching

Caching is very important to SEO nowadays. Page speed  is one of main factors, used by Google to determine sites position. When we have already prepared Our website and don’t plan dramatic changes in its look in the near future, then we can ‘tell Google’ to have some site elements stored longer in users browser cache. In this way, when someone visits site second time, it’s loaded much faster!

Here’s some nice working piece of code for You. When You use WordPress just past it in You .htaccess before ‘Begin WordPress’. When using different platform or build site without any CMS platform take elements, which suits Your needs (images).

We can see, if it works and speeds our site up using Google Speed Insights. Tell me how Your score have changed in few minutes

Excluding traffic (bot) – ban certain IP addresses

Sometimes server is overloaded with tons of bot requests. We see, that our site is loading longer (for example in Google Search Console, in mentioned Google Speed Insights or when analyzing stats directly on server site), then it can be because of large amount of bot traffic.

Using .htaccess we can exclude traffic from specific IP addresses (responsible for bot traffic):

Last thing – very important. Protect Your .htaccess

And how to generate .htaccess file. You can do it easily using standard Notepad available in Windows. Just choose “save as” option, then choose file format “all files” (not .txt) and name file “.htaccess”. That’s all!

That’s all for my first post. I would be very gratefull, if have helped anyone! If You have any questions or just want to share opinions, discuss this topic/or also want to discuss different ones –  feel free to do it.

Have fun and just keep growing online!

Related Post