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 Slim Basics & Twig Templates Including & Running Slim

Paul Yorde
Paul Yorde
10,497 Points

How to fix The requested URL was not found on this server error for the hello/name url?

I have the Rewrite commands in the .htaccess file like so:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

I have the Slim hello code in the index.php file:

<?php 

require __DIR__ . '/vendor/autoload.php';
date_default_timezone_set ( "America/New_York" );

// $log = new Monolog\Logger('name');
// $log->pushHandler(new Monolog\Handler\StreamHandler('app.log', Monolog\Logger::WARNING));
// $log->addWarning('Foo');

$app = new \Slim\Slim();
$app->get('/hello/:name', function ($name) {
    echo "Hello, $name";
});
$app->run();

?>

Yes, the monolog is working as is the datetime function.

I have tried to modify the base as instructed also, though I realize that really isn't the error I'm getting. Also, just for my FYI, does this look like the way to make the absolute path to my .htaccess file?

RewriteBase /Applications/MAMP/htdocs/SimplePHPWebsite/

Update: I've added code from the next video which is partially working, Snippet:

$app->get('/', function() {
    echo 'Hello, this is the homepage.';
});

$app->get('/contact', function() {
    echo 'contact us.';
});

This works for the homepage, but not for the contact page.

I'm using localhost:8888 with MAMP

I want to confirm something. Does it work if you go to localhost:8888/index.php/hello/name and localhost:8888/index.php/contact ?

Paul Yorde
Paul Yorde
10,497 Points

No, neither of those work.

2 Answers

Daryl Peterson
Daryl Peterson
7,812 Points

A couple of things come to mind. 1) Make sure your file is .htacess 2) Add this to the top of your .htacess file then check your logs RewriteEngine On RewriteLog "/path/to/rewrite.log" RewriteLogLevel 9

Paul Yorde
Paul Yorde
10,497 Points

Awesome, that worked. I must have missed turning rewrite on in the video.

Thank you Dayrl, One big Best Answer coming your way!

Daryl Peterson
Daryl Peterson
7,812 Points

Place the following @ the top of page and see if it gives you any output

ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1);

Paul Yorde
Paul Yorde
10,497 Points

Added it to the top of index.php file, but no errors displayed.