Nash
Nash

Reputation: 562

Why is my route in Laravel returning a 404 error?

So in my routes.php file I have this:

Route::get('contact', function() {
   return view('contact');
});

When I go to domain.com/contact I get a return error. However when I put:

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

and go to domain.com the page appears. Any idea what could be causing this?

Full Routes file:

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

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

Route::get('contact', function() {
    return view('contact');
});

php artisan route:list returns:

+--------+----------+---------+------+---------+------------+
| Domain | Method   | URI     | Name | Action  | Middleware |
+--------+----------+---------+------+---------+------------+
|        | GET|HEAD | /       |      | Closure | web        |
|        | GET|HEAD | contact |      | Closure | web        |
+--------+----------+---------+------+---------+------------+

Upvotes: 4

Views: 3822

Answers (1)

Nash
Nash

Reputation: 562

Ok so I fixed my issue. If anyone else has this issue make sure mod_rewrite is enabled on your server. You do this by going to the terminal and entering

a2enmod rewrite

then typing

service apache2 restart

It now works like a charm.

Upvotes: 4

Related Questions