You can configure redirect rules to perform various redirects. Some can be set up using your hosting control panel, and others can be set up in your .htaccess file. Usually, redirects set up in the .htaccess file can be fine-tuned. The biggest benefit of using the .htaccess file is that it persists after a server migration.
Note:
- We recommend you use the [.htaccess] file to create redirects.
Redirects in the [.htaccess] file will be carried over when we upgrade or migrate servers. - Due to a known bug in cPanel on LiteSpeed-based servers, Wild Card redirects set in cPanel > Redirects do not function as intended.
Editing .Htaccess File
In cPanel, the [.htaccess] file remains hidden by default. You need to make it visible so you can edit it.
Make the file visible:
- Go to cPanel > File Manager.
- Click "Settings" from the top right corner.
- Check mark [*] "Show Hidden Files (dotfiles)".
- Click "Save".
- Done!
Edit the .htaccess file:
- Go to cPanel > File Manager.
- Navigate to the
public_html
directory. It is the root directory of your primary domain.
If you are editing the .htaccess file of an addon domain or subdomain, navigate to the root directory for that domain/subdomain.
You can view the root directories of all domains in cPanel > Domains. - Select the .htaccess file and click "Edit".
- Click "Save Changes" after modifying the file.
- Done!
Redirect HTTP to HTTPS
This will create the following redirects:
- http://yourdomain.com to https://yourdomain.com
- http://www.yourdomain.com to https://www.yourdomain.com
- http://yourdomain.com/page to https://yourdomain.com/page
- http://www.yourdomain.com/page to https://www.yourdomain.com/page
cPanel:
- Go to cPanel > Domains.
- Set "Force HTTPS Redirect" to "On" next to your domain name.
- Done!
.htaccess:
Add the following redirect rules at the top (before all other rules) in the .htaccess file:
##### Start MechanicWeb Redirect Rule
##### Remove this section if not needed
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
</IfModule>
##### End MechanicWeb Redirect Rule
Redirect HTTP to HTTPS with WWW
This will create the following redirects:
- http://yourdomain.com to https://www.yourdomain.com
- http://www.yourdomain.com to https://www.yourdomain.com
- http://yourdomain.com/page to https://www.yourdomain.com/page
- http://www.yourdomain.com/page to https://www.yourdomain.com/page
- https://yourdomain.com to https://www.yourdomain.com
- https://yourdomain.com/page to https://www.yourdomain.com/page
.htaccess:
Add the following redirect rules at the top (before all other rules) in the .htaccess file:
##### Start MechanicWeb Redirect Rule
##### Remove this section if not needed
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%2%{REQUEST_URI} [R=301,L]
</IfModule>
##### End MechanicWeb Redirect Rule
Redirect Domain1 to Domain2
This will create the following redirects:
- https://yourdomain1.com to https://yourdomain2.com
- https://www.yourdomain1.com to https://yourdomain2.com
- https://yourdomain1.com/page to https://yourdomain2.com/page
- https://www.yourdomain1.com/page to https://yourdomain2.com/page
cPanel:
- Go to cPanel > Redirects.
- Select "Permanent (301)" in "Type".
- Select your domain or subdomain in "https?://(www.)?".
- Enter
https://yourdomain2.com
in "Redirects to". - Select [*] Redirect with or without www.
- Select [*] Wild Card Redirect.
- Done!
*To redirect to www.yourdomain2.com, replace yourdomain2.com
with www.yourdomain2.com
.
*Make sure to replace yourdomain2.com
with your actual domain name.
Note:
cPanel currently has a known bug on LiteSpeed-based servers that creates a conflict between the redirect rule and existing rules.
Check the redirect after configuring it in cPanel. If it does not work, delete it from cPanel > Redirects and add the .htaccess rule.
.htaccess:
Add the following redirect rules at the top (before all other rules) in the .htaccess file:
##### Start MechanicWeb Redirect Rule
##### Remove this section if not needed
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourdomain1.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.yourdomain1.com$
RewriteRule (.*)$ https://yourdomain2.com/$1 [R=301,L]
</IfModule>
##### End MechanicWeb Redirect Rule
*To redirect to www.yourdomain2.com, replace yourdomain2.com
with www.yourdomain2.com
*Make sure to replace yourdomain1.com
and yourdomain2.com
with your actual domain names.
Redirect to Maintenance Page
This will create the following redirects:
- https://yourdomain.com/ to https://yourdomain.com/maintenance.html
- https://yourdomain.com/page to https://yourdomain.com/maintenance.html
Note:
*Make sure to replace yourdomain.com/maintenance.html
with your actual maintenance page URL.
.htaccess:
Add the following redirect rules at the top (before all other rules) in the .htaccess file:
##### Start MechanicWeb Redirect Rule
##### Remove this section if not needed
<IfModule mod_rewrite.c>
ErrorDocument 503 /maintenance.html
RewriteEngine on
RewriteCond %{REQUEST_URI} !=/maintenance.html
RewriteCond %{REMOTE_ADDR} !=123.123.123.123
RewriteRule ^.*$ - [R=503,L]
</IfModule>
##### End MechanicWeb Redirect Rule