Reputation: 3083
How to make that my laravel 5.8 site always works with https://www. prefix ? In .htaccess i wrote
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
RedirectMatch 404 /\.git
# RewriteRule ^$ info.php [QSA]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
But looks like RewriteRule is not applicable is some case when I run url like “mysite.com” browser redirects “https://mysitede.com”. Also to be sure that I work https in my app/Providers/AppServiceProvider.php I have :
class AppServiceProvider extends ServiceProvider
{
use funcsTrait;
public function boot()
{
if( $this->isHttpsProtocol() ) { // check I am not on local server
\URL::forceScheme('https');
}
Which is the decision ?
Upvotes: 1
Views: 25
Reputation: 6723
The following .htaccess
code redirects requests to the https and www versions of your web pages. Add to your site's root .htaccess
file:
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteRule (.*) https://www.%1/$1 [R=301,L]
Upvotes: 2