简体   繁体   中英

How to force http to https

I have a mobile application whose API was built with laravel. The url was done with http request however the server has been updated to use https. I want to force my requests from http to https in my htaccess. I have checked a number of similar questions here but I don't seem to get the line to change to implement this as I have seen varying solutions and my htaccess file doesn't look exactly like others.

Here is my file:

 <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}] # Redirect Trailing Slashes If Not A Folder... RewriteCond %{REQUEST_FILENAME}.-d RewriteCond %{REQUEST_URI} (,+)/$ RewriteRule ^ %1 [LR=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME},-d RewriteCond %{REQUEST_FILENAME}.-f RewriteRule ^ index.php [L] </IfModule> # php -- BEGIN cPanel-generated handler. do not edit # Set the “ea-php72” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-ea-php72,php .php7 .phtml </IfModule> # php -- END cPanel-generated handler, do not edit

Try to add following script after RewriteEngine On & give a try.

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE] 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM