Skip to content
Advertisement

Laravel 8.53 – Routing doesnt work on any of pages

Solution

The solution was found thanks to @Gert B.

Simply add to your Laravel application any virtual host (I added for mine) laravel1.test

How to add Virtual host: Go to C:WindowsSystem32driversetchosts

add line:

127.0.0.1 laravel1.test (or your virtual host name)

And add this to your vhosts(in case of using xampp) in C:xamppapacheconfextra httpd-vhosts

<VirtualHost *:80>
        ServerName www.laravel1.test
        ServerAlias laravel1.test
        DocumentRoot "C:xampphtdocsLaravel1public"
        
        <Directory "C:xampphtdocsLaravel1public">
            # use mod_rewrite for pretty URL support
           RewriteEngine on
            # If a directory or a file exists, use the request directly
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            # Otherwise forward the request to index.php
            RewriteRule . index.php

            # use index.php as index file
            DirectoryIndex index.php
            # ...other settings...
            # Apache 2.4
            Require all granted
           
            ## Apache 2.2
            # Order allow,deny
            # Allow from all
       </Directory>
   </VirtualHost>

I can’t pass the problem with routing in Laravel 8.5 framework. I know there have been many requests about this problem so far but any of given solutions didnt help in my case. I will show Frontend code, since backend is the same thing and also doesnt work. Right now, the only thing that works is index.php.

I know thanks to newest Laravel all bugs are hidden under simple error 404.

Bug image

I already tried:

  • Changing in apache/conf/httpd solution AllowOverride All
  • Clearing whole cache and routes cache
  • Any possible misspells in code

Still, without any working anwser.

My FrontendController at app/Http/Controllers

namespace AppHttpControllers;

use IlluminateHttpRequest;

class FrontendController extends Controller
{
    public function index()
    {
        return view('frontend.index');
    }

    public function object()
    {
        return view('frontend.object');
    }

    public function article()
    {
        return view('frontend.article');
    }


    public function person()
    {
        return view('frontend.person');
    }

    public function room()
    {
        return view('frontend.room');
    }

    public function roomSearch()
    {
        return view('frontend.roomsearch');
    }

}

My web.php at app/routes

use IlluminateSupportFacadesRoute;
use AppHttpControllersFrontendController;


##Frontend routes

Route::get('/','FrontendController@index')->name('index');
Route::get('/object','FrontendController@object')->name('object');
Route::get('/article','FrontendController@article')->name('article');
Route::get('/person','FrontendController@person')->name('person');
Route::get('/room','FrontendController@room')->name('room');
Route::get('/roomSearch','FrontendController@roomsearch')->name('roomSearch');


##Backend routes
Route::group(['prefix'=>'admin'],function(){

    Route::get('/','BackendController@index')->name('adminHome');

    Route::get('/cities','BackendController@cities')->name('cities');
    Route::get('/myObjects','BackendController@myobjects')->name('myObjects');
    Route::get('/profile','BackendController@profile')->name('profile');
    Route::get('/saveObject','BackendController@saveobject')->name('saveObject');
    Route::get('/saveRoom','BackendController@saveroom')->name('saveRoom');

});

.htacces file in app/public

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
       Options -MultiViews
   </IfModule>
   Options +FollowSymlinks
   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>

My routes image

Advertisement

Answer

Solution

The solution was found thanks to @Gert B.

Simply add to your Laravel application any virtual host (I added for mine) laravel1.test

How to add Virtual host: Go to C:WindowsSystem32driversetchosts

add line:

127.0.0.1 laravel1.test (or your virtual host name)

And add this to your vhosts(in case of using xampp) in C:xamppapacheconfextra httpd-vhosts

<VirtualHost *:80>
        ServerName www.laravel1.test
        ServerAlias laravel1.test
        DocumentRoot "C:xampphtdocsLaravel1public"
        
        <Directory "C:xampphtdocsLaravel1public">
            # use mod_rewrite for pretty URL support
           RewriteEngine on
            # If a directory or a file exists, use the request directly
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            # Otherwise forward the request to index.php
            RewriteRule . index.php

            # use index.php as index file
            DirectoryIndex index.php
            # ...other settings...
            # Apache 2.4
            Require all granted
           
            ## Apache 2.2
            # Order allow,deny
            # Allow from all
       </Directory>
   </VirtualHost>
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement