Set up domain redirects

Author: HOSTTEST Editorial   | 31 Jul 2017

02-in-drei-schritten-zum-passenden-domainnamen.jpgDomain redirects are important for controlling visitor flows on your own web presence. But how can they be set up on your own web hosting?

Webmasters managing larger websites will sooner or later come across the topic of redirects. This involves controlling visitor flows by redirecting traffic to specific pages of your own web project or implementing restructuring on your own website. Redirects can also be used to reuse the same web content on different domains without the risk of duplicate content. Domain redirects are also used in the context of indexing in search engine management. There are several different ways available for the technical implementation of redirects, which we would like to explain in more detail in this article.

Why are domain redirects important?

Domain redirects are typically used when web content from a specific URL is no longer available or has been moved to another URL. However, the old URL is still linked in other web documents or browser bookmarks. If website visitors arrive at a URL through these links and the content is no longer available, a 404 error occurs. This is not optimal for either visitors or search engines. It is better if requests can be redirected to a suitable alternative URL.

Especially with large websites such as magazines or online shops, it is common for content under a specific URL to no longer be available. For example, when a product is no longer being sold or outdated information is removed from the website. In these cases, redirecting to relevant alternative content makes sense so that visits to the old URL do not lead to dead ends, causing valuable traffic and link strength to be lost.

There are other use cases in the field of search engine management. For example, website content can be made accessible through different web addresses without creating duplicate content, which is usually negatively evaluated by search engines. The alternative web addresses are simply redirected to the prioritised domain using domain redirects.

How to set up domain redirects?

There are different approaches to implement domain redirections on your own website. In general, you can distinguish between server-side redirection and client-based redirection. The first option should always be preferred as it is more effective and secure due to higher compatibility with all user agents (browsers, bots, etc.). Client-based redirection should only be used when server-side redirection is not feasible due to technical limitations.

Server-Side Redirection

Server-side domain redirection can be implemented either through the .htaccess configuration file or by including a PHP script. The webmaster can choose which HTTP status code to use. Domain redirections can be marked as either temporary or permanent:

HTTP Status Code 301 - Moved Permanently
The old URL is declared invalid, and the requested content is permanently available at the new URL.

HTTP Status Code 302 - Moved Temporarily
The old URL remains valid, and the requested content is temporarily available at the new URL.

Redirection via .htaccess

The .htaccess file is a configuration file of the Apache web server where directory-specific settings for a domain and its subdirectories can be made. The redirection rule can be directly entered here:

If the entire web address needs to be redirected to another domain, the .htaccess configuration file must be in the root directory and contain the following entry:
Redirect 301 / http://www.new-domain.co.uk/

If only a specific page needs to be redirected to another URL, the .htaccess configuration file must be in the root directory and contain the following entry:
Redirect 301 /old-directory/old-document.html http://www.domain.co.uk/new-directory/new-document.html

If the Apache web server has the "mod_rewrite" software module available, the following entry can be made:
RewriteEngine On
RewriteRule ^old-directory/old-document.html$ http://www.domain.co.uk/new-directory/new-document.html [L,R=301]

Redirection via PHP

As an alternative to the .htaccess configuration file, domain redirection can also be activated using a specific command through a PHP script. For example, the index.php file can be supplemented with the following code:

Client-Based Redirection

If server-side redirection cannot be enabled due to technical limitations, webmasters must resort to client-side redirection. In this case, the HTML meta tag "refresh" or corresponding JavaScript can be used.

Redirection via HTML Meta Tag

To implement redirection via HTML meta tag, an HTML file with the following code must be included in the header of the webpage:

Redirection via JavaScript

To implement redirection via JavaScript, the following code must be included in the webpage:

Domain redirections are a useful tool for controlling content and visitor flows on larger websites. Webmasters of such web projects should therefore familiarise themselves with this topic. Those running a small website on simple web hosting are less likely to be affected by this. However, if you operate a larger web project on a Virtual Private Server or a Dedicated Server, then you should definitely keep domain redirection in mind.

Write a comment


    Tags for this article

  • Domain

More web hosts


More interesting articles

Is it worth buying a premium domain

For certain domain names, website operators have to dig deep into their pockets. But is the investment in a premium doma...

Earning Money with Domain Trading - How It Works

How to Make Money by Trading Domains