3

I have a simple route defined in routes.php on top of any route:

Route::get('/test', function () {
echo 'hello';
});

It is working when access through http but it gives:

The requested URL /test was not found on this server.

When I try to access through https.

I have searched a lot on internet but couldn’t find any solution.

My main page is loading with both http and https but other routes not working. Do I need some extra configurations?

Edit:

.htaccess:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On


    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]


</IfModule>

Please guide me.

Thanx.

user2517610
  • 265
  • 2
  • 8
  • 25
  • I think this will work even in 5.2. http://stackoverflow.com/questions/28402726/laravel-5-redirect-to-https – aldrin27 Apr 21 '16 at 05:09

3 Answers3

5
  • Update the APP_URL in your .env file so it starts with https:// instead of http://:

    APP_URL=https://yourserver.com

  • Add this to your SSL Apache config (on Ubuntu: default-ssl.conf):

<Directory /var/www/public/>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  allow from all
</Directory>
maesk
  • 157
  • 3
  • 13
  • "Doesn't work for me" would be more appropriate, @RaeIan. Nothing has changed in Laravel 5.8 (https://laravel.com/docs/5.8/releases) that would make this fix obsolete. APP_URL is still there and the rest is Apache configuration that has nothing to do with the Laravel version. You simply have a different problem. – maesk Sep 06 '19 at 09:22
  • 1
    it works as expected, perfect thank you mate! – kollein Jan 11 '22 at 02:39
1

I am facing the same issues and I resolved it by simply modified my .htaccess file. Generally this is problem with our rewrite module. try this hope it work for you.

 <IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Also make sure folder structures match on local and production servers.

Ankur Tiwari
  • 2,715
  • 2
  • 21
  • 40
0

If someone will have a problem with infinity loop in Laravel there is a solution:

RewriteEngine On

# If we receive a forwarded http request from a proxy...
RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]

# ...or just a plain old http request directly from the client
RewriteCond %{HTTP:X-Forwarded-Proto} =""
RewriteCond %{HTTPS} !=on

# Redirect to https version
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Hubb
  • 33
  • 2