How do I create a redirect for my site?

These rules should be added to your .htaccess file located in your public_html folder.

This rule will redirect all none SSL traffic to the SSL (https) portion of your site: 

RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^ https://yourdomain.com%{REQUEST_URI} [NS,R,L]

In addition use one of the following rules, www.yourdomain.com is different from yourdomain.com. You will need to redirect all traffic from one to other.

If your SSL is for www.yourdomain.com you will want to use the first rule to redirect all yourdomain.com traffic to www.yourdomain.com. This rule will direct all traffic to yourdomain.com to www.yourdomain.com.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourdomain.com$
RewriteCond %{REQUEST_URI} !^.*www.*$
RewriteRule ^(.*)$ http://www.yourdomain.com [R=301]

If your SSL is for yourdomain.com you will want to use the first rule to redirect all www.yourdomain.com traffic to yourdomain.com. This rule will direct all traffic to www.yourdomain.com to yourdomain.com.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.yourdomain.com$
RewriteRule ^(.*)$ http://yourdomain.com [R=301]

*replace yourdomain.com with the domain you need to redirect to.

Was this answer helpful?

 Print this Article

Also Read

How do I get different character sets to display in HTML?

Many web browsers display Western Character Encoding (ISO-8859-1) by default. This means that...

Can I add my own CGI scripts?

Our LINUX web servers have the capability to run CGI scripts in your own 'cgi-bin' directory....

How to flush DNS cache in my PC?

How to flush DNS cache in Linux / Windows / Mac Flush dns to get a new name resolution. Also...

Do I use localhost or remotemysqlhost for my mysql connection ?

You can view whether your account is using localhost or remotemysql host in your cPanel...

What is the meaning of owner, group, and everyone in the permissions panel?

- Owner defines the permissions set for your main FTP account. - Group defines permissions valid...