0

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 [L,R=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
mykoman
  • 1,715
  • 1
  • 19
  • 33
  • Does this answer your question? https://stackoverflow.com/questions/12999910/https-to-http-redirect-using-htaccess – Stefan Apr 26 '20 at 19:06
  • @Stefan that link describes https to http rerouting instead of http to https. I probably would have been able to work around it but I currently understand close to nothing about htaccess – mykoman Apr 26 '20 at 19:38

1 Answers1

0

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

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE] 
Karthick
  • 324
  • 3
  • 12
  • It didn't work when I placed the code after RewriteEngine. Am I supposed to replace it with some other code or just include the code? It shows the error: Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException upon request via postman – mykoman Apr 26 '20 at 13:34
  • Found some [article](https://stackoverflow.com/questions/35399126/laravel-5-htaccess-https-redirect-on-post-routes-doesnt-work). Just check whether it can work out for you. – Karthick Apr 26 '20 at 13:56