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

Mathieu.l's avatar

The requested URL /task was not found on this server.

Hi, i just started the tutorial "quickstart" of laravel and im stuck at this error:"The requested URL /task was not found on this server."

I have laravel installed on my web server (ubuntu) and to acces my example i use this url : "/quickstart/public"

that's in my routes.php :

Route::post('/task', function (Request $request) {
        $validator = Validator::make($request->all(), [
            'name' => 'required|max:255',
        ]);

        if ($validator->fails()) {
            return redirect('/')
                ->withInput()
                ->withErrors($validator);
        }

        $task = new Task;
        $task->name = $request->name;
        $task->save();

        return redirect('/');
    });

is it my apache conf or rerouting im not sure.

0 likes
13 replies
skliche's avatar

@Mathieu.l Try the following .htaccess:

DirectoryIndex index.php
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
    RewriteEngine On
    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]
    RewriteRule .? %{ENV:BASE}/index.php [L]
</IfModule>

and have a look at using the asset() helper, example with explanation regarding problems with the tutorials here.

Snapey's avatar

You need to sort out your web server so that public is NOT part of the URL.

The exact method will depend on your development environment but you should be looking to set the root folder to public.

Mathieu.l's avatar

i changed my htaccess and add asset() in my code and i still get the same error

but i would prefer to work like @skliche if possible

i start in (serverIP)/quickstart/public and when i click on new task im redirect on (serverIP)/task and then get the error

Snapey's avatar

Then ok, carry on.... you will experience 'odd' issues, and you will not be sure if it is your 'wonky' setup

As for your first question, then of course you should be accessing /quickstart/public/task or just take the leading / off the Route::post

Mathieu.l's avatar

oh i think a got some progress: the error code is now: he requested URL /quickstart/public/task was not found on this server.

skliche's avatar

@Mathieu.l The route you posted above is the POST route. When you click on a link "new task" that would create a GET request so you also need a route like

Route::get('task', function() {
    // return the view
});
Mathieu.l's avatar
/**
 * Show Task Dashboard
 */
Route::get('/', function () {
    return view('tasks', [
        'tasks' => Task::orderBy('created_at', 'asc')->get()
    ]);
});

/**
 * Add New Task
 */
Route::post('/task', function (Request $request) {
    $validator = Validator::make($request->all(), [
        'name' => 'required|max:255',
    ]);

    if ($validator->fails()) {
        return redirect('/')
            ->withInput()
            ->withErrors($validator);
    }

    $task = new Task;
    $task->name = $request->name;
    $task->save();

    return redirect('/');
});

/**
 * Delete Task
 */
Route::delete('/task/{id}', function ($id) {
    Task::findOrFail($id)->delete();

    return redirect('/');
});
skliche's avatar

@Mathieu.l Ah, sorry, just had a look at the tutorial, you don't need a GET route. In your view tasks.blade.php there should be a form tag. Make sure to use either asset() or url() helper there to generate the action URL, e.g.:

<form action="{{ url("/task") }}" method="POST" class="form-horizontal">
Mathieu.l's avatar

i replaced this line in tasks.blade.php and i still get this error: Not Found

The requested URL /quickstart/public/task was not found on this server.

skliche's avatar

The error means that the request doesn't even reach your "/quickstart/public/index.php" file. Did you replace the .htaccess file in your "/quickstart/public" directory and is your Apache configured to evaluate it? The AllowOverride directive in the Directory block that handles your project's files should not be set to "None".

Where did you put the project's files? Somewhere under your user's home directory or somewhere else?

Mathieu.l's avatar

my home directory is /var/www/ and my project is located in /var/www/quickstart/public/ i change my config in /etc/apache2/apache2.conf and i have this:

<Directory /var/www/>

    Options Indexes FollowSymLinks

    AllowOverride All

    Require all granted

</Directory>

should I add a new directory to point on my public folder?

skliche's avatar

@Mathieu.l Sorry for the late reply. I tried to reproduce your problem and created the quick start tutorial in my server's home directory (/Library/WebServer/Documents) instead of my user's home directory. This is the relevant entry from my httpd.conf:

<Directory "/Library/WebServer/Documents">
    Options FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

Also make sure the necessary module is loaded:

LoadModule rewrite_module modules/mod_rewrite.so

You don't have to add a new directory to point to the public folder. After changing the configuration do not forget to restart Apache (apachectl restart) or the changes won't have any effect at all.

Additionally I have performed the following changes to the project's directory to make sure that the web server's process is able to access anything and write to the storage directory:

sudo chgrp -R _www /Library/WebServer/Documents/quickstart2
sudo chmod -R 775 /Library/WebServer/Documents/quickstart2/storage

_www is the group the web server/httpd is run as.

Then I have changed the .htaccess as outlined before and used the url() helper to generate links / form action urls. Works fine, the URL is http://localhost/quickstart2/public. Since you are using Ubuntu some things might be different but the above should show you what needs to be done.

Please or to participate in this conversation.