All routes (route) of Laravel return ERROR 404

2

I have just created my first project with Laravel, and I am following all the steps little by little. But I find myself stuck with an error that I can not solve.

When editing the web.php file in the routes directory, it happens that no route you add works. Only the main route to the root works. All others return ERROR 404 .

Example:

Route::get('/', function () {
    return  ('bienvenida');
});

Route::get('/hola', function()
{
    return ('hola mundo');
});

By opening domain.com/public/ I get the message " welcome ".

By opening domain.com/public/hola I get a 404 error .

However, if I go to domain.com/public/index.php/hola I get the " hello world ".

This is not how the routes should work. That is, you should not have to type "index.php" to continue writing the route. Does anyone know this problem and know how to fix it?

Thank you very much in advance!

    
asked by Alberto Torre 16.12.2018 в 00:33
source

1 answer

0

I have found a solution. Although I do not understand the details of why it works like that.

I have entered the administration panel of my "dominio.com", and have made it point directly to / public. In this way, it is no longer necessary to put domain.com/public. Domain.com leads directly to public.

Also, I have edited the htaccess within public and added RewriteBase /

It looks like this:

<IfModule mod_rewrite.c>
    RewriteBase /
    <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>

Another detail that may be worth mentioning, is that this happens to me with a hired hosting of 1and1 (now Ionos). Looking for solutions to this problem, the people who asked had in common that all this happens to them with this type of hosting.

    
answered by 16.12.2018 в 14:57