Ad

Can't Route In Laravel Framework

- 1 answer

I create an app with Laravel framework in PHP.

I have a problem with routing.

.htaccess file looks like this:

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

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

routes.php:

<?php
get('/', function () {
return view('welcome');
});


get('1', function() { return 'Je suis la page 1 !'; });
get('2', function() { return 'Je suis la page 2 !'; });

When I load http://localhost:63342/game/public/, server loads welcome.blade.php file, so it's okey. But when I want to load http://localhost:63342/game/public/1, I got error: 404 Not Found. I use appache server and I already enabled 'mod_rewrite' action. What can be problem?

Ad

Answer

I found solution. I enabled mod_rewrite action for apache server in httpd.conf, but problem was, that I didn't set correct directory path in this file for my projects.

It should have looked like this:

DocumentRoot "/Applications/MAMP/htdocs"

<Directory "/Applications/MAMP/htdocs" >
    Options Indexes FollowSymLinks
    AllowOverride All 
</Directory>

Hope, it helps someone in future.

Ad
source: stackoverflow.com
Ad