Pre-requirements
- Access to your cPanel account.
- Basic knowledge of .htaccess and redirect types (301, 302).
- Ability to use cPanel's File Manager or SSH to manage .htaccess files.
Introduction
When setting up redirects in cPanel using the Redirect feature, the settings are written to the .htaccess file. However, sometimes redirects fail to work due to pre-existing content in the .htaccess file. This guide will walk you through how to troubleshoot and fix redirect issues by modifying or renaming the .htaccess file, and using the correct redirect types for your domain.
Steps to Fix Redirect Issues in cPanel
Step | Description | Linux Command | Windows Command (via SSH) |
---|---|---|---|
1. List Directory Contents | Check the contents of your public_html directory to ensure the .htaccess file exists. |
|
|
2. Check .htaccess File | Check if the .htaccess file contains the redirect directive. |
|
|
3. Rename .htaccess | If the .htaccess file has conflicting content, rename or move it before recreating the redirect. |
|
|
4. Set Up Redirects in cPanel | Use cPanel’s Redirect feature to create the desired redirect. Choose between permanent (301) or temporary (302) redirects. | No specific command needed. Use the cPanel interface under Domains > Redirects. | |
5. Test the Redirect | Visit your browser and test the redirect to ensure it works as expected. | No specific command needed. Simply visit the redirected URL in your browser. | |
6. Force HTTPS Redirect (Optional) | If you want to redirect visitors from HTTP to HTTPS, enable the "Force HTTPS Redirect" option in cPanel. | Use cPanel’s Force HTTPS Redirect feature under Domains. |
Examples of Redirect Types
Permanent Redirects (301)
- Redirect entire site:
Redirect 301 / https://$domain_name.com/
- Redirect page:
Redirect 301 /original.html https://$domain_name.com/new.html
- Redirect directory:
Redirect 301 /old-directory https://$domain_name.com/new-directory
Temporary Redirects (302)
- Redirect entire site:
Redirect 302 / https://$domain_name.com/
- Redirect page:
Redirect 302 /original.html https://$domain_name.com/new.html
- Redirect directory:
Redirect 302 /old-directory https://$domain_name.com/new-directory
Additional Steps for Handling Redirects
If you need to redirect a domain while keeping the original domain in the browser’s address bar, consider using the “Addon Domains” option in cPanel. You can also redirect from HTTP to HTTPS using the Force HTTPS Redirect option under Domains in cPanel.
Gotchas to Avoid
- Conflicting Rules in .htaccess: Be careful not to overwrite important rules when editing the .htaccess file.
- Testing Redirects: After setting up redirects, always test them in different browsers to ensure proper functionality.
- SSL Redirects: If you're redirecting from HTTP to HTTPS, ensure your SSL certificates are properly installed.
This guide covers how to troubleshoot and fix redirect issues in cPanel by managing the .htaccess file and using cPanel's Redirect feature. By following the steps provided, you can ensure smooth redirect functionality, whether you're using permanent (301) or temporary (302) redirects. Don’t forget to test your redirects and enable Force HTTPS Redirect for secure traffic.
For more tutorials and domain management tips, visit our Knowledge Base.