Home Physics CS HTML
Night More

Revise Now

Cambridge AS levels

Physics Computer Science

Programming and Coding

Learn HTML Html Reference

More

What do you want
to do?

Contact us Donate Support More Services Send a tweet Social media




more topic chapters

Htaccess for SEO - Full SEO Guide

We will discuss all the different ways the htaccess file can be used to increase the seo of your website

1. Increasing pagespeed by compressing and caching

2. Redirecting to error pages (404)

3. Redirecting from Http to Https

4. Creating SEO friendly Urls

Now we will see how you can access and edit the Htaccess file. Just watch this video to get started! The Htaccess file is a powerful file that can control how your website works and so every web developer needs to know how it works

After you know how to edit the htaccess file, all you need to do is copy the codes and paste it on the document and save it

Don't worry if you don't understand! We will explain each step


Compression and caching

Why do we cache and compress our webpages and files? To make our webpages load faster and improve user experience

Think about it? Who likes a slow loading website?

The SEO of a website heavily depends on the pagespeed of the webpage especially when it's a new website

If you have a slow pagespeed, google will probably not rank your website high in searches because, slow pages damages your SEO

We will see one aspect of how pagespeed could be improved using the Htacces file

We will see how to compress your files and also allow caching

#Compressions
<ifmodule mod_deflate.c>
  # Compress HTML, CSS, JavaScript, Text, XML and fonts
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml
  # Remove browser bugs (only needed for really old browsers)
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  Header append Vary User-Agent
</ifmodule>


#Cache
<IfModule mod_expires.c>  
  # Turn on the module.
  ExpiresActive on
  # Set the default expiry times.
  ExpiresDefault "access plus 2 days"
  ExpiresByType image/jpg "access plus 1 month"
  ExpiresByType image/svg+xml "access 1 month"
  ExpiresByType image/gif "access plus 1 month"
  ExpiresByType image/jpeg "access plus 1 month"
  ExpiresByType image/png "access plus 1 month"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType text/javascript "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
  ExpiresByType application/x-shockwave-flash "access plus 1 month"
  ExpiresByType image/ico "access plus 1 month"
  ExpiresByType image/x-icon "access plus 1 month"
  ExpiresByType text/html "access plus 600 seconds"
</IfModule> 

You really don't need to know how this works so just copy and paste this on your htaccess file

But We will explain it!

The Compression part is used to compress any images, text or any other files. This increase your pagespeed by alot and also decrease the storage used.

The Cache section is used to cache or temporarily store data such as images and text for some time in the user's computer and the server. This allows fast access of files because, the files are partly saved and stored

If you want you can change how long you want each cache to be stored

ExpiresByType image/x-icon "access plus 12 month"

This makes sures the favicon or the icon of the website is cached for a year!

For things that don't change much, we can use a larger time period but, if you are always editing and changing it like text, it's best to keep it for one day!

HTTP to HTTPS

Https is a more secure version of Http. It uses SSL to encrypt the data. In order words, it makes the website more secure

We will talk how to force your website to redirect Http to Https!

For this to work, you need to have SSL on your website. If your hosting site does not provide the SSL feature, then this code will not work

We can recommend you to use a better Hosting site which offers SSL Hosting for a low price

Copy and paste this code on your Htaccess file

#HTTPS Redirections
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{ENV:HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>

This forces the url to redirect to the Https url

For example, if the visitor enters http://youtube.com instead of https://youtube.com, it will be anyways redirected to https://youtube.com

Redirecting to Error pages

When your website redirects to a custom made error page it makes it look better. It also improves the SEO of your overall website

Copy an paste the code

RewriteEngine On
ErrorDocument 404 /404.shtml


You need to create a webpage which is at the root of the domain and has the extension .shtml

The same can be done for other errors such as 500

RewriteEngine On
ErrorDocument 500 /500.shtml


Creating SEO friendly Urls

For some hosting sites they don't allow this function to be overwritten so we recommned you to ask your hosting site, whether they allow webpages to remove any file extensions from webpages

Nevertheless, try copying this code and paste it

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
This to remove the .html
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
This to remove the .php

Now you can remove all the .html from your urls. This will take time

href="https://revisezone.com/Html/Physics"

It is not neccessary to do this as it is very time consuming to remove all the .html from your urls

Revise Zone recommend you to not use this code as it is a very time consuming adjustment

There are more functions and uses of the Htaccess file but, this tutorial only focuses on the ways to increase the seo of your website!