Brook Preloader

Laravel Redirect HTTP to HTTPS via .htaccess

Editing .htaccess in cPanel File Manager
Note: Backup your website in case something goes wrong.

Login to cPanel
Files > File Manager > Document Root for:
Now select the domain name you want to access
Check “Show Hidden Files (dotfiles)”
Click “Go”

After a new tab or window opens, look for the .htaccess file.
Right click on the .htaccess file and click on “Code Edit” on the menu.
A dialogue box may pop up asking about encoding. Click “Edit” button to continue.
Edit the file “Save Changes” when done. Test your website to make sure it is done correctly. In case, there is an error, restore to the previous version and try again. Once you are done, click “Close” to close the window.

Redirecting HTTP to HTTPS

  1. Redirect All Web Traffic
    If you have existing code in your .htaccess, add the following:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

  1. Redirect Only a Specific Domain

For redirecting a specific domain to use HTTPS, add the following:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

Leave A Comment

Your email address will not be published. Required fields are marked *

Categories

Archives