Skip to content
Advertisement

API routes using Https on laravel gives 404

I created an Laravel API.

First, it was using HTTP, I needed to change it to use https.

So I created an account on Cloudflare and since then when I go to my API endpoints:

GET: https://www.traapp.tk/api/data/20190809 it gives a 404:

Not Found

The requested URL /api/data/20190809 was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

I also have a POST request and that returns a 404 to.

.htacces

<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>

api.php

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});


Route::get('data/{date}', 'MainController@index');

Route::post('route', 'MainController@getAllRoutesOfACertainDay');

MainController

public function index ($date) {
        $responseServer = json_decode($this->makeRequest(str_replace('DATE', $date, env('BASE_URL') . env('SCHEDULES'))),true);
        return $this->respond($responseServer);
    }

I tried solutions like these:

Force Laravel to use HTTPS version

How to implement HTTPS in laravel 5.4

Advertisement

Answer

That’s a 404 from your Web server not from your laravel. I guess you forgot to change the declared port in your Vhost configuration from 80 to 443.

Cloudflare example:

<VirtualHost *:443>
    ServerName.....
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement