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 trialMichael Rockett
40,365 Points/hello/name not working still shows 404 page
Hi, I'm still only getting the 404 page at the moment when I add /hello/name to the url. I've adding the .htaccess as well.
I should add I'm not doing this in workspaces I'm doing it on my computer and php is working fine
Here is my code
<?php
require 'vendor/autoload.php'; date_default_timezone_set("Europe/London");
//$log = new Logger('name'); //$log->pushHandler(new StreamHandler('app.txt', Logger::WARNING)); //$log->addWarning('Foo');
$app = new \Slim\Slim();
$app->get('/hello/:name', function ($name) { echo "Hello, $name"; });
$app->run();
?>
Thanks, Mike
10 Answers
Michael Rockett
40,365 PointsThanks for the help but I've solved the issue now. It was really simple. I called the project php composer practice which didn't work as this caused spaces in the url. I've renamed the project with no spaces and it now works fine
Thanks, Mike
Ted Sumner
Courses Plus Student 17,967 PointsAny time. You can probably guess by my questions that I was looking for a server problem.
michael7williams
9,638 PointsThis solved my issues in wamp too. I think you could supplement the %'s for spaces in the url and it will work as well.
Ted Sumner
Courses Plus Student 17,967 Pointsdid you do the steps in the video starting at 3:00? They also get a 404 error and show you what to do to get a result with that code.
Michael Rockett
40,365 PointsYeah I did that, I added hello and then a name but I still get 404. In the video however at this point they get not found which means I must be doing something wrong before then.
Ted Sumner
Courses Plus Student 17,967 PointsWill you post a snapshot? Use the camera icon in the upper right of the screen to create the snapshot. Post the link it creates.
Michael Rockett
40,365 PointsI'm not sure how to take a snap shot and can't find the camera icon (Im on a pc) but this is the url http://localhost/php%20Composer%20Practice/hello/mike
Michael Rockett
40,365 Pointsand this is what I get...
404 Page Not Found
The page you are looking for could not be found. Check the address bar to ensure your URL is spelled correctly. If all else fails, you can visit our home page at the link below. Visit the Home Page
Ted Sumner
Courses Plus Student 17,967 PointsYou are not in Workspaces. My bad.
Did the monolog work?
Michael Rockett
40,365 PointsI think so it's in my vendor folder
Ted Sumner
Courses Plus Student 17,967 PointsDid you create the htaccess file? Many text editors will not open the file as a .htaccess, so it is created without the period. The you have to rename the file .htaccess and ensure it is in the project root file.
Michael Rockett
40,365 Pointsyep I did that, I added the code while it was a htaccess.txt file then renamed it to .htaccess
Ted Sumner
Courses Plus Student 17,967 PointsPlease post the contents of your .htaccess file.
Michael Rockett
40,365 PointsRewriteEngine On
Some hosts may require you to use the RewriteBase
directive.
If you need to use the RewriteBase
directive, it should be the
absolute physical path to the directory that contains this htaccess file.
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L]
Michael Rockett
40,365 PointsSorry I forgot to use the markdown sheet
Ted Sumner
Courses Plus Student 17,967 PointsNo problem. It looks right to me, but I am not an expert on this.
Ted Sumner
Courses Plus Student 17,967 PointsI assume you use XAMPP. Is it running? If not, is whatever you are using as server software running?
Michael Rockett
40,365 PointsYes I'm using XAMPP and it's running apache
Sajid Latif
Full Stack JavaScript Techdegree Student 22,368 PointsI have the same issue. After inserting /hello/myname is stills shows the 404 error. Help needed :)
Ted Sumner
Courses Plus Student 17,967 PointsDid Monolog work when you did that part of the course?
Michael Rockett
40,365 PointsHi, I found that my problem was that there were spaces in the name of my urlso it was like php practice/hello/myname. When I changed the project name to phppractice the url then had no spaces and this fixed it for me. Could this be the same problem your having?
Sajid Latif
Full Stack JavaScript Techdegree Student 22,368 PointsYes, the monolog is working, since the 404 error is appearing, which is great. But the concern is about the name, which I put in the url after the /Hello/myname.
Ive made the exact same course which hampton did and I had the problem there. Now Im doing it on my live website, where I wont to use slim, BUT the exact same problem is showing with the /Hello/myname so I was wondering if it is the .htaccess file.
MIchael. Ive tried with differnt urls. :(
Sajid Latif
Full Stack JavaScript Techdegree Student 22,368 Points... WANT to use slim and not WONT to use SLIM :)
Ted Sumner
Courses Plus Student 17,967 PointsWe need to see code. A code snapshot if you are working in Workspaces or copy and paste. Please use the Markdown Cheatsheet formatting for copied code. A workspace snapshot is made with the camera icon in the upper right of the workspace.
Ted Sumner
Courses Plus Student 17,967 Pointsso the issue you have is only with the contact page?
Ted Sumner
Courses Plus Student 17,967 PointsBecause the whole site is working except the link to the page, we know the error is somewhere in the link. In this case I was able to correct the problem by changing line 30 on main.twig to:
<?php
<a href="{{siteUrl('/contact')}}">Contact</a>
I did not play with the contact name to figure out what was wrong, but this works.
If you have finished the course you missed making this change and the change to the About link. You will want to find the video on that. The About link should be:
<?php
<a href="{{ baseUrl()}}" class="selected">About</a>
If you have not finished the course, keep going.
Sajid Latif
Full Stack JavaScript Techdegree Student 22,368 PointsThanks for your fast reply. I appriciate it a lot :)
Now this work. But do you know why this doesnt work for me? I try to insert my name in URL
/Hello/myname
but it doesn not show my name, but the 404 error. Thats strange. Ive also tried it on my live website and still the same. Maybe you have the answer?
<?php
$app = new \Slim\Slim();
$app->get('/hello/:name', function ($name) {
echo "Hello, $name";
});
$app->run();
Ive made a snapshot of it.
Sergey Podgornyy
20,660 PointsTry to visit /hello/myname
instead /Hello/myname
Ted Sumner
Courses Plus Student 17,967 PointsTed Sumner
Courses Plus Student 17,967 PointsIn the future please format your code following the markdown cheatsheet linked below.