4

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        |
+--------+----------+---------+------+---------+------------+
Nash
  • 542
  • 1
  • 7
  • 16
  • can you share more codes of your routes.php? maybe all the routes in it? this could be due to having route group with prefix on top of the route you are having error – Tommy Lee Aug 03 '16 at 02:05
  • It is the first route I'm trying to get to work, but I posted it as I have it. – Nash Aug 03 '16 at 02:14
  • 1
    try to add a "/" in front ur contact route... `Route::get('/contact', function....` – Tommy Lee Aug 03 '16 at 02:25
  • @TommyLee That didn't work, I also tried 'contact/' and '/contact/' – Nash Aug 03 '16 at 02:29
  • is this on ur local development or a production server? – Tommy Lee Aug 03 '16 at 02:34
  • 1
    @Nash please try this command `php artisan routes` or `php artisan route:list` and see if your route is there ! – Ismail RBOUH Aug 03 '16 at 02:34
  • 1
    `php artisan route:list` if u are using laravel ver >5 – Tommy Lee Aug 03 '16 at 02:36
  • +--------+----------+---------+------+---------+------------+ | Domain | Method | URI | Name | Action | Middleware | +--------+----------+---------+------+---------+------------+ | | GET|HEAD | / | | Closure | web | | | GET|HEAD | contact | | Closure | web | +--------+----------+---------+------+---------+------------+ – Nash Aug 03 '16 at 02:56
  • Better to paste it somewhere like http://kopy.io – Andrew Fox Aug 03 '16 at 03:06
  • 3
    That's really weird ! Please try to clear the cache `artisan route:clear` who knows ! – Ismail RBOUH Aug 03 '16 at 03:18
  • Show us the error log `laravel/storage/logs`. – azeós Aug 03 '16 at 03:26
  • @azeós there is no error in the log for this. It is just going to 404 and not returning any kind of error. – Nash Aug 03 '16 at 03:54
  • @IsmailRBOUH I cleared the route cache and I"m getting the same result – Nash Aug 03 '16 at 03:59
  • Are you using `php artisan serve` or your server ? – Ismail RBOUH Aug 03 '16 at 04:03
  • I will note that I went to /index.php/contact and it worked... I don't know why it would do that, but it is – Nash Aug 03 '16 at 04:03
  • @Nash if that worked then you are using either `Apache/Nginx` and you need to check your `.htaccess/location` ! – Ismail RBOUH Aug 03 '16 at 04:07
  • Possible duplicate of [Laravel quick start guide route not working](http://stackoverflow.com/questions/16897504/laravel-quick-start-guide-route-not-working) – patricus Aug 03 '16 at 04:20
  • @IsmailRBOUH I found the answer, my mod_rewrite wasn't enabled. As soon as I did that on apache everything works fine. Thanks for taking your time to trya nd help me. – Nash Aug 03 '16 at 04:35
  • @Nash that was my next guess ;) good luck. – Ismail RBOUH Aug 03 '16 at 04:36

1 Answers1

4

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.

Nash
  • 542
  • 1
  • 7
  • 16