I have a Laravel project. and I used Godaddy. Recently, I installed an SSL certificate on my website so when I type https://example.com in the browser it works but when I write example.com, it connects by HTTP.
To fix that, I added these lines to my root folder’s .htaccess file:
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
But this redirects to me https://example.com/public.
I added two htaccess one is in the root folder and the second one is in public folder.
first htaccess code :
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L,NC]
Second htaccess code is :
Options -MultiViews -Indexes
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
How can I achieve this https://example.com
.
Thanks in advance!
4
Answers
Here is the Solution,
Try this code:
I am using this to redirect.
Tried every solution but this worked for me on Laravel 6.0, use this by creating .htaccess file in root folder rather than /public/.htaccess file.