09/01/2018
Updated: Sep 9, 2018 3:05 PM

Site versioning with .htaccess

A small note on how on the Apache server to organize the versioning of a static site using the .htaccess file.

The implementation of the versioning of a static site through .htaccess is as follows:

  1. At the root of the site we put the folder with the name of the version, for example 1.2.0;
  2. Also, put the .htaccess file in the root of the site, with the following directives:
    <IfModule mod_rewrite.c>
      RewriteCond %{REQUEST_URI} !^/1.2.0/
      RewriteCond %{HTTP_HOST} ^(www\.)?vadimfedorov\.
      RewriteRule ^(.*)$ /1.2.0/$1 [L]
    </IfModule>

Now Apache server will redirect all requests to the specified folder, that is, 1.2.0.

This configuration makes it easy to release new versions, or, if something went wrong, roll back to the previous stable version. It's enough just to change the version in the .htaccess file.

Illustrations:
At the root of the site we put the folder with the name of the version, for example 1.2.0
At the root of the site we put the folder with the name of the version, for example 1.2.0
Also, put the .htaccess file in the root of the site, with the following directives
Also, put the .htaccess file in the root of the site, with the following directives