Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jgravois's avatar

Laravel 5.3 - I don't want the '/' route to redirect to login

I am finding that any route placed in /Routes/web.php has the Auth middleware applied. I have a website of public content with an option to register to access additional assets but there are 12 pages available without authentication. I have this in my /Routes/web.php and the site goes to the login page immediately,

Route::get('/', 'HomeController@index');
Route::get('/home', 'HomeController@index');

Auth::routes();

How can I route the public pages correctly?

0 likes
7 replies
bobbybouwmann's avatar

You can create a new file and add it to your RouteServiceProvider. Something like this should do:

protected function mapPublicRoutes()
{
    Route::group([
        'namespace' => $this->namespace,
    ], function ($router) {
        require base_path('routes/public.php');
    });
}

Make sure you call this new method in your map function as well

public function map()
{
    $this->mapWebRoutes();

    $this->mapApiRoutes();

    $this->mapPublicRoutes();
}

And of course don't forget to create a new public.php file in your routes directory.

An alternative method would be removing the auth middleware from the mapWebRoutes method and make your own route group in the web.php file ;)

TheNodi's avatar

@jgravois

The web.php file is inside a route group defined in the RouteServiceProvider and by default it gets the web middleware group.

I don't see auth being applied to it. Check those two locations too see if you've 'auth' middleware in the service provider or in the web middleware group.

Snapey's avatar
Snapey
Best Answer
Level 122

It would be insane for auth to be applied to all routes. Something is not right with your setup, or you are assessing the problem incorrectly.

Try php artisan route:list to verify what middleware is applied.

Could it be that you have specified auth in a controller constructor?

Show your home controller?

jgravois's avatar

route:: list gives me

arty route:list
+--------+----------+------------------------+-------+------------------------------------------------------------------------+--------------+
| Domain | Method   | URI                    | Name  | Action                                                                 | Middleware   |
+--------+----------+------------------------+-------+------------------------------------------------------------------------+--------------+
|        | GET|HEAD | /                      |       | App\Http\Controllers\HomeController@index                              | web,auth     |
|        | GET|HEAD | api/user               |       | Closure                                                                | api,auth:api |
|        | GET|HEAD | home                   |       | App\Http\Controllers\HomeController@index                              | web,auth     |
|        | GET|HEAD | login                  | login | App\Http\Controllers\Auth\LoginController@showLoginForm                | web,guest    |
|        | POST     | login                  |       | App\Http\Controllers\Auth\LoginController@login                        | web,guest    |
|        | POST     | logout                 |       | App\Http\Controllers\Auth\LoginController@logout                       | web          |
|        | POST     | password/email         |       | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail  | web,guest    |
|        | GET|HEAD | password/reset         |       | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web,guest    |
|        | POST     | password/reset         |       | App\Http\Controllers\Auth\ResetPasswordController@reset                | web,guest    |
|        | GET|HEAD | password/reset/{token} |       | App\Http\Controllers\Auth\ResetPasswordController@showResetForm        | web,guest    |
|        | GET|HEAD | register               |       | App\Http\Controllers\Auth\RegisterController@showRegistrationForm      | web,guest    |
|        | POST     | register               |       | App\Http\Controllers\Auth\RegisterController@register                  | web,guest    |
+--------+----------+------------------------+-------+------------------------------------------------------------------------+--------------+
jgravois's avatar
$this->middleware('auth');

that WAS in the constructor for HomeController

imwebby's avatar

Just wanted to add to this, I encountered the same problem.

After running - php artisan make:auth

My home page became restricted and required login.

I went back and checked the controller and sure enough as with jgravois HomeController was now part of the auth middleware.

looks like running make:auth completely overwrote my home controller.

  • it makes sense that automatically installing the auth routes would do this, but if you do not know to look for it it can drive you crazy!

So.. I went back an actually read the whole section in the documentation and they do warn you:

"This command should be used on fresh applications and will install a layout view, registration and login views, as well as routes for all authentication end-points. A HomeController will also be generated to handle post-login requests to your application's dashboard."

1 like

Please or to participate in this conversation.