Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Introducing MVC Frameworks in PHP Building an MVC Project Routes

Contact Route not working. Getting a 404.

I cannot get the contact route working. I get an 404.

<?php

use Slim\Http\Request;
use Slim\Http\Response;

// Routes

$app->get('/contact', function (Request $request, Response $response, array $args) {
    return $this->view->render($response, 'contact-form.phtml', $args);
});

$app->get('/[{name}]', function (Request $request, Response $response, array $args) {
    // Sample log message
    $this->logger->info("Slim-Skeleton '/' route");

    // Render index view
    return $this->view->render($response, 'about.phtml', $args);
});

1 Answer

I solved this issue. I forgot to add the .htaccess file to the public folder.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]