How to Configure a Htaccess Redirect

Posted on by Jay Allen
Reading Time: 2 minutes

Say you have decided to change domain names, or you have one address on your site that you want to redirect to a completely different location. Using htaccess redirects you can send visitors to the new site automatically!

Htaccess is a hidden file that can be found, normally, in your website’s public_html folder. To modify it you will need to SSH into your server account and modify the file using your favorite command line text editor, or you can create the file yourself and upload it to the server using FTP/SFTP or SCP.

Important Notes: You should always back up important files before you modify them. If you do not know how to back up files using SSH please see this guide.

Your website’s htaccess file may already contain important settings that need to remain in place. If your htaccess file has existing settings you will need to add the new code to what is already there. You may need to seek assistance from your website designer or, if you are using a content management system, contact your site’s software developers for help adding new htaccess settings. Do not delete the existing htaccess file unless it is either empty or you are sure it is ok to do so.

If you have any questions regarding what is appropriate for your website, especially if your site was built for you and you aren’t completely familiar with your site code, feel free to contact our support team, and we will be happy to help.

Simple Redirects

To move an individual page on your site:

Redirect 301 /old.html http://www.test.com/new.html

This will send any visitors who are trying to go to test.com/old.html to test.com/new.html.

Breaking down the command: Redirect tells the server it will be sending this traffic to another destination. 301 informs the visitor or search engine indexing the site that the redirect is a permanent move. If you are only redirecting traffic temporarily you will want to use 302 instead of 301.

To move an entire website (the whole domain name):

Redirect 301 / http://www.test.com/

This is often used when changing an existing domain to a new domain name.

Simple Rewrites

Rewrites are similar to redirects in that they point one target URL to another URL, but this is actually converted by the web server itself while handling the traffic. Think of it as using a pencil and eraser to change a name as opposed to saying “See new name on attached note.”

Important Note: If your site utilizes an SSL certificate to secure traffic for an online store, form, or other secure page you will need to make sure that you do not redirect https:// links to http:// links. Redirecting secure traffic (https) to an insecure (http) address will probably scare your customers.

Rewrite www to non-www site address

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^test\.com
RewriteRule (.*) http://test.com/$1 [R=301,L]

(This will automatically send visitors who type in http://www.test.com to http://test.com)

Rewrite non-www to www site address

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^test.com [NC]
RewriteRule ^(.*)$ http://www.test.com/$1 [L,R=301]

(This will automatically send visitors who type in http://test.com to http://www.test.com)

You can also read up on Meta Tags if you would like to explore redirect alternatives to using .htaccess.

===

Liquid Web’s Heroic Support is always available to assist customers with this or any other issue. If you need our assistance please contact us:
Toll Free 1.800.580.4985
International 517.322.0434
support@liquidweb.com
https://my.liquidweb.com/

Avatar for Jay Allen

About the Author: Jay Allen

Latest Articles

Blocking IP or whitelisting IP addresses with UFW

Read Article

CentOS Linux 7 end of life migrations

Read Article

Use ChatGPT to diagnose and resolve server issues

Read Article

What is SDDC VMware?

Read Article

Best authentication practices for email senders

Read Article