thelematics.com
thelematics

We build and transform businesses through strategy, design and development

Delivering sustainable digital solutions, leading the industry in web design, app design and digital marketing.

Welcome to an award winning boutique digital agency

Sustainable Digital Assets

It all starts with a domain name. From basic online apps, websites, platforms, to eCommerce and enterprise solutions.
read more

Modern eCommerce

Revenue in the eCommerce market is projected to reach $31,330M in 2022. Welcome onboard!
read more

On-Demand Platforms

Providing solid, out-of-the box app hosting, ad-hoc support and reliable web solutions.
read more

Reliable Growth Trends

Experience incredible performance delivered by our Robust Cloud Hosting Infrastructure.
read more

It all starts with a domain name

We are an AUDA partner, investing into domain name research, management and registration procedures.
A domain name is an address on the internet which people can use to find resources like websites, or send email. Our domain registration service runs via CONNECT, 2u2 Web Technologies.
We dedicate our time to bring you the best in the business.

Explore some of our latest and ongoing projects.

Banno's Bees and Honey

Banno's Bees and Honey

ACT, Australia, NSW, QLD, SA, VIC, WA
The Knife Kompany

The Knife Kompany

Australia, Germany
Samba World Percussion

Samba World Percussion

Australia, Germany, QLD

We are a web design and development agency, building websites that drive traffic, engagement, and conversion for industry-leading brands and startups.

A business website with lead-generation or sales goals must be designed to convert. Calls-to-action that capture contact information or make sales are the focal point of inbound marketing.
Darlo Drama

Darlo Drama

Darlo Drama is the home of beginners acting in Darlinghurst, Sydney NSW. An independent theatre, bringing confidence, creativity and community, through a sense of play and discovery, to adults of all ages…
My Hygge Home Australia

My Hygge Home Australia

“My Hygge Home® offers fresh, contemporary products to spoil oneself or as a premium gift for friends and families of which you can feel proud. We’re all about bringing a unique and…
Specialised Cleaning Products

Specialised Cleaning Products

First and foremost, the Specialised Cleaning Products are an established family-owned and family-operated business that works to meet all cleaning product needs. The Specialised Cleaning Products family business was established over 20…
The Knife Kompany

The Knife Kompany

The Knife Kompany is a family business run by the owners. All products sold are absolutely genuine and sourced from reputable Australian and worldwide distributors. Modern knife steel is very high quality…
Garage Fitness Girl

Garage Fitness Girl

Penny Barnshaw went from being a full-time personal trainer, working in and working out at a gym for almost 20 years, to taking her entire business online and working full time at…
St Euphemia College

St Euphemia College

St Euphemia College is one of the exceptional Victorian schools that is utilising the Digital School's (www.digitalschools.com.au) excellent set of tools and digital assets (Digital Schools + Meet Smart-Engage Plan) to present,…
Life Celebrations with Joy

Life Celebrations with Joy

Weddings, Naming, Renewal of Vows, End of Life, Celebrations - Brisbane Celebrant for All Life’s Occasions. A real Life Celebrant, Joy Williams from Life Celebrations at Gold Coast QLD, with whom a…
Suresh Menon, HR Specialist

Suresh Menon, HR Specialist

Suresh Menon is an outstanding Human Resources Manager, with over 40 years of experience in building an outstanding employee and service culture to develop passionate and committed people. Suresh was responsible for…
Banno's Bees and Honey

Banno's Bees and Honey

After many years of saying we need more bees for pollination the talk of this new fangled flowhive got Banno thinking, well its time to step up and become a beekeeper. Once…
One Pressure Wash

One Pressure Wash

One Pressure Wash utilises the most state of the art vehicles and equipment to remove any stain from anywhere. Unlike many high pressure cleaning companies, the One Pressure Wash don’t require the…
Neopilates

Neopilates

NeoPilates seeks to offer a world class Pilates experience at our studio located in Thane West. We are a studio with a singular focus on Pilates, providing programmes designed by Australian instructors…
Direct Portable Buildings

Direct Portable Buildings

Over the years the Direct Portable Buildings from Sunshine Coast QLD, Australia, fine-tuned their services so they are simple and so you walk away over the moon with your purchase and have…
Rosenvale Vineyards

Rosenvale Vineyards

"Thinking outside the box and working through challenges across each vineyard is the true foundation of Rosenvale’s success." ~ The Rosenvale Vineyard's history goes back through generations of exceptional and dedicated winemakers.…
Samba World Percussion

Samba World Percussion

Whether you need advice on which instrument to buy, or you have an enquiry on buying for education authorities, at Samba World Percussion Australia they'll love to hear from you! Most of…
Compliance Workplace Solutions

Compliance Workplace Solutions

Compliance Workplace Solutions (CWS) provide the all-inclusive, practical advice and HR solutions across the full spectrum of human resource and safety legislation requirements. Compliance Workplace Solutions approach is collaborative and adaptive. Compliance…
Urangan Caravan Storage

Urangan Caravan Storage

Secure and Affordable Caravan, Boat and Vehicle Storage with 18 Large Covered Sites 9m x 3m for Long Term Rental. Urangan Caravan Storage is conveniently located in Urangan at Harvey Bay QLD,…
Whoops Online

Whoops Online

In short, Whoops Online takes care of Domain registration, Professional Cloud hosting, Email Management, Web Applications, Online Security, SEO, SEM, Digital Agency Services, Advertising, Social Media, Visual Communications, Newest Technology Trends and…
Gensolve

Gensolve

Gensolve.com is a wonderful practice management solution SaaS company. The Gensolve company consists of the most wonderful people, contributing some of the most wonderful services made up completely on their own. Gensolve…
Upschool.co

Upschool.co

Upschool's 'why' is to create a kinder and more compassionate world. This supposedly underpins what they teach. We highly enjoyed working on providing its functionality and bringing its core idea to full…
Stonewood Homes

Stonewood Homes

For over 30 years Stonewood Homes have been building beautiful, quality homes for Kiwi families with our design range rated number one amongst our peers. Our unmatched quality and service make us…
Kindbox.com

Kindbox.com

The kindbox mission states that the choices we make today have a direct impact on the world of tomorrow. Therefore, at kindbox.com, they aim to empower mostly private school organisations, school representatives,…

We are a boutique agency, driven by the creation of unique and memorable brand experiences. Get a visually attractive design from concept to a final result.

To make your digital on-boarding simple and customer friendly we provide you with ongoing support, digital tools and oustanding attention. Ask us any question you like.
enquire here
Copyright 2022, Thelematics Inc. All rights reserved. Powered by ⚡ CONNECT, 2u2 Web Technologies
heartusercartmagnifiercrossmenuarrow-right "; A beginner's guide to creating redirects in an Apache .htaccess file - thelematics.com
Home / Stories / / A beginner's guide to creating redirects in an Apache .htaccess file

A beginner's guide to creating redirects in an Apache .htaccess file

April, 2022
A beginner's guide to creating redirects in an Apache .htaccess file

Use the .htaccess file to manage web sites on shared web hosting platforms.

Have you ever felt a need to change the configuration of your website running on an Apache web-server without having root access to server configuration files (httpd.conf)? This is what the .htaccess file is for.

The .htaccess file provides a way to make configuration changes to your website on a per-directory basis. The file is created in a specific directory that contains one or more configuration directives that are applied to that directory and its sub-directories. In shared hosting, you will need to use a .htaccess file to make configuration changes to your server.

Common uses of .htaccess file

The .htaccess file has several use cases. The most common examples include:

  • Redirections for certain URLs
  • Load custom error pages, like 404 pages
  • Force your website to HTTPS instead of HTTP
  • Allow or deny specific IP addresses access to your website
  • Password-protect certain directories on your server

When not to use .htaccess?

The .htaccess file is commonly used when you don't have access to the main server configuration file httpd.conf or virtual host configuration, which only happens if you have purchased shared hosting. You can achieve all of the above-mentioned use cases by editing the main server configuration file(s) (e.g., httpd.conf) or virtual host configuration files, so you should not use .htaccess when you have access to those files. Any configuration that you need to put in a .htaccess file can just as effectively be added in a <Directory> section in your main server or virtual host configuration files.

Reasons to avoid using .htaccess

There are two reasons to avoid the use of .htaccess files. Let's take a closer look at them.

First: Performance - When AllowOverride is set to allow the use of .htaccess files, httpd will look for .htaccess files in every directory starting from the parent directory. This will cause a performance impact, whether you're using it or not. The .htaccess file is loaded every time a document is requested from a directory.

To have a full view of the directives that it must apply, httpd will always look for .htaccess files starting with the parent directory until it reaches the target sub-directory. If a file is requested from directory /public_html/test_web/content, httpd must look for the following files:

  • /.htaccess
  • /public_html/.htaccess
  • /public_html/test_web/.htaccess
  • /public_html/test_web/content/.htaccess

So, four file-system accesses were performed for each file access from a sub-directory content even if the file is not present.

Second: Security - granting users permission to make changes in .htaccess files gives them full control over the server configuration of that particular website or virtual host. Any directive in the .htaccess file has the same effect as any placed in the httpd configuration file itself, and changes made to this file are live instantly without a need to restart the server. This can become risky in terms of the security of a webserver and a website.

Enable the .htaccess file, if not enabled yet

To enable the .htaccess file, you need to have sudo/root privileges on the server.

Open the httpd configuration file of your website:

/etc/httpd/conf/test.conf

You should add the following configuration directive in the server's virtual host file to allow the .htaccess file in the DocumentRoot directory. If the following lines are not added, the .htaccess file will not work:

</VirtualHost>
<Directory /var/www/test.com/public_html>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

In the case of shared hosting, this is already allowed by the hosting service providers. All you need to do is to create a .htaccess file in the public_html directory to which the service provider has given you access and to which you will upload your website files.

Redirect URLs

If your goal is to simply redirect one URL to another, the Redirect directive is the best option you can use. Whenever a request comes from a client on an old URL, it forwards it to a new URL at a new location.

If you want to do a complete redirect to a different domain, you can set the following:

# Redirect to a different domain
Redirect 301 "/service" "https://newdomain.com/service"

If you just want to redirect an old URL to a new URL on the same host:

# Redirect to a URL on the same domain or host
Redirect 301 "/old_url.html" "/new_url.html"
Load a custom 404 Error page

Kubernetes and OpenShift

For a better user experience, load a custom error page when any of the links on your website point to the wrong location or the document has been deleted.

To create a custom 404 page, simply create a web page that will work as a 404 page and then add the following code to your .htaccess file:

ErrorDocument 404 /error/pagenotfound.html

You should change /error/pagenotfound.html to the location of your 404 page.

Force the use of HTTPS instead of HTTP for your website

If you want to force your website to use HTTPS, you need to use the RewriteEngine module in the .htaccess file. First of all, you need to turn on the RewriteEngine module in the .htaccess file and then specify the conditions you want to check. If those conditions are satisfied, then you apply rules to those conditions.

The following code snippet rewrites all the requests to HTTPS:

# Turn on the rewrite engine
RewriteEngine On

# Force HTTPS and WWW
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [OR,NC]
RewriteCond %{https} off  
RewriteRule ^(.*)$ https://www.test-website.com/$1 [R=301,L]

Let's go through each line.

RewriteEngine on turns on the RewriteEngine module. This is required; otherwise, conditions and rules won't work.

The first condition checks if www is entered. [OR, NC] stands for no case, which means even if the entered URL has a mix of upper or lowercase case letters.

Next, it checks if the HTTPS protocol was already entered by the user. %{https} off means that HTTPS protocol was not used.

When the RewriteCond is satisfied, we use RewriteRule to redirect the URL to HTTPS. Note that in this case, all URLs will be redirected to HTTPS whenever any request is made.

Wrap up

Website owners often use the .htaccess file to control the behavior of their website. In this article, we have covered the basics of the .htaccess file and some common use cases in place on most of the websites.

Copyright 2022, Thelematics Inc. All rights reserved. Powered by ⚡ CONNECT, 2u2 Web Technologies
heartusercartmagnifiercrossmenu