Overview

During the life of a web site it may undergo a name change and rather than have visitors hit the old web site you may wish to have them automatically redirected to a new web address. To achieve this, web servers allow administrators (and web site owners with access to the file system) to implement re-directs using a special file.

The Apache Web Server uses a file called a “.htaccess” file, this file enables fine grained control at a directory or sub-directory level. To implement a redirect from an old site to a new site, you can create a .htaccess file using a text editor on your computer and upload it to the web site. The change will take effect immediately.

Instructions

The following lines need to be entered into the .htaccess file:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^oldsite.com.au [NC,OR]
RewriteCond %{HTTP_HOST} ^www.oldsite.com.au [NC]
RewriteRule ^(.*)$ https://www.newsite.com.au [L,R=301,NC]

Ensure that the name is .htaccess the “.” is significant!

FTP it into your web site document root and test. If it fails without an error contact your web site administrator to verify that the web server config allows .htaccess files (normally enabled by default).

Was this article helpful?

Related Articles