View all Products Close Menu Menu
Create redirects using the .htaccess file
Updated Thursday January 28th 2021 / Category Advanced

Using the inbuilt cPanel tools

If you’d prefer to add simple redirects, cPanel has an inbuilt redirect tool that will do this for you.

If you want to do anything that is outside of the fairly basic functionality of the cPanel redirect tool, you may want to consider manually editing your .htaccess file to create more advanced redirects.

Adding redirects manually

Your .htaccess files provide a means to make configuration changes in how directories/files route. With this file you can redirect certain requests – such as force visitors to the HTTPS version of your site.

This file is usually located in your public_html directory, as well as the root directory for any add-on or sub-domains.  Here’s a few of the most common uses of these types of redirects. For the most effective use it is best to insert these at the top of your .htaccess file.

Rewrite a directory to be SSL/HTTPS access only

RewriteEngine On
RewriteCond %{SERVER_PORT} !443
RewriteRule ^(.*)$ https://www.mywebsite.com/directory [R,L]

Rewrite a specific file in a directory to be SSL/HTTPS access only

RewriteEngine on
RewriteCond %{SERVER_PORT} !443
RewriteRule ^specificfile.php$ https://www.mywebsite.com/directory/specificfile.php [R=301,L]

Rewrite the URL to force visitors to ‘www.’

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.mywebsite.com [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [R=301,L]

Redirect any request for the root directory to forward to a subdirectory

RewriteEngine on
RewriteCond %{HTTP_HOST} www.example.com [NC]
RewriteCond $1 !^test/
RewriteRule ^(.*)$ http://www.example.com/test/$1 [L]

Redirect ‘yourdomain.com’ to ‘subdomain.yourdomain.com’

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com
RewriteRule ^directory(.*) http://subdomain.yourdomain.com$1 [R=301,L]

Redirect ‘www’ to ‘subdomain.yourdomain.com’

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

Can’t find the answers you're looking for? Check out these other methods of support!