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 Building Websites with PHP Contact Form & Sending Email Named Routes

'/contact' route not routing

My contact link results in a 404, however my about link works fine.

In my index.php I have

$app->get('/',function() use($app){
    $app->render('about.twig');
})->name('home');

$app->get('/contact',function() use($app){
    $app->render('contact.twig');
})->name('contact');

and in my main.twig

<a href="{{ baseUrl() }}" class="selected">About</a>

<a href="{{ siteUrl('contact') }}">Contact</a>

the HTML that is rendered shows the correct file path. Why am I getting a 404 on this when the about works just fine? It is driving me nuts. Please pardon the odd formatting.

2 Answers

Aamir Mirza
Aamir Mirza
25,077 Points

You forgot the backslash (/) before "contact" in your main.twig. So instead of:

<a href="{{ siteUrl('contact') }}">Contact</a>

It should be:

<a href="{{ siteUrl('/contact') }}">Contact</a>

I hope that works :)

Thank you for the response. It turned out that I had neglected to move the htdocs file when I moved the folder.