The Redirect feature allows you to send all of the users that access a domain or a particular page to a different URL. This can be done by using cPanel’s “Redirects” feature or by using .htaccess file if the cPanel redirection does not work properly.
In here we shall discuss few helpful .htaccess codes
Non-www to www Redirection
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
R=301 >> The Permanent (301) option will notify the visitor’s browser to update its records.
R=302 >> The Temporary (302) option will not update the visitor’s bookmarks.
This .htaccess rule will redirect the naked domain name to its www domain name. Replace the domain.com with your own domain name.
http to https Redirection
Following rules will redirect all users to https instead of the ordinary http, based on the port numbers (80 or 443).
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.domain.com/$1 [R,L]
OR
RewriteEngine On
RewriteCond %SERVER_PORT !443
RewriteRule (.*) https://www.domain.com/ [R]
For a Better redirection, we can use the following .htaccess rule which is not based on Port no. This seems to be the most reliable redirection, since it forces all users to https site, with no Port checking or any other extra steps.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Redirect Your Domain To A Subfolder
Primary Domain on most hosting services usually use “public_html” folder (or root folder) to store its files. The following is a simple way to redirect your primary domain to a subfolder on that domain.
For example anything for “www.domain.com” or “domain.com” would be forwarded to a specific folder, requests with other subdomains will be ignored.
This is useful if your WordPress blog is installed to a subfolder and you want the main domain to forward to it.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteCond %{REQUEST_URI} !folder/
RewriteRule (.*) /folder/$1 [L]
Please try to add the following line in the top of your .htaccess file if you are getting a “Continuous Redirect Loop” error in the web browser.
ErrorDocument 401 default
If you are trying to redirect the CMS websites such as Wordpress, Joomla or Magento to its www or SSL websites and are not working neither by using cPanel redirection nor by .htaccess file, then you can try to change the site URL and home URL to the destination address and clear the CMS and browser cache.
If you require help, contact SupportPRO Server Admin