I'll-Be-Back
I'll-Be-Back

Reputation: 10828

Laravel, Admin controllers - 403 Forbidden

I am trying to create Admin controllers in the default controller folder. I have created "admin" folder in the "controller" folder.

In the routes file:

Route::get('/admin', 'admin/AdminController@showAdminIndex');

AdminController.php file:

namespace Admin;

class AdminController extends \BaseController {

    public function showAdminIndex()
    {
        return "Hello World";
    }

}

I get an error on the browser:

403 Forbidden

What went wrong?

Upvotes: 3

Views: 8837

Answers (1)

lukasgeiter
lukasgeiter

Reputation: 152900

The problem is that you have an admin subfolder in the public directory. The .htaccess that ships with Laravel only boots the application if no directory or file exists at the requested URI (that's why CSS and other assets still work)

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

You basically have two options here:

  1. Rename either one, the route or the folder. If public/admin is for assets you could put it in public/assets/admin for example.

  2. Change your .htaccess to not ignore folders for rewriting

Like:

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

Upvotes: 17

Related Questions