Jeffrey, I am a hige fan, lifetime member of Laracasts and evangelist of Laravel & Laracasts. That fake typing at the beginning almost had me spit beer on my laptop. Hahahahaha. Its awesoem how many experienced PHP guys are watching these videos here and there. Including me.
I'm really loving this series. I work with PHP and Javascript in my job, and I've learned everything I know about these languages just through experience and google. The basics I'm learning here is really refreshing and it's really helping me in my job, so thank you! To be honest, before you got to parse_url function call, I thought you'd have to pull out preg_match() and thought "ooh, this is moving quickly!" haha. Nice to see the PHP devs already thought of that! Keep up the great content!
I love this series! A few years ago I had really trouble with understanding routing. Your first PHP series made it so clear, it was like a sudden awakening. The other thing I enjoy here is that you try different concepts. Your first series was so object oriented, and now you have a more functional approach. Will you refactor to classes where appropiate? ;) Also, two years ago I was about to quit web developement. But your dedication made me resist that. Your one of my favorite teachers, and also guitarist like me. All the best to you. :)
Agreed how much better is his new stuff in the past he was to fast but his new series he explains it so much better and he charges 12 pound a month you can't go wrong
Up until this point, you were teaching us MVC model without even metioning it, its just so natural.....i really love your style of teaching things, thank you !
Nice and clean as always... I was runing some tests and this behavior when you access some address that doesn't exists only works in php server. With wamp and laragon you get 404 error probably because of apache and the index.php is never called. So if you're having this issue, try just run the tutorial codes like Jeffrey in a simple "php -S localhost" and it should work.
Thank you for clearing this up for me, i had the same 404 problem earlier on wamp server. but i have one question, i'm running a laravel app on WAMP and it works, i'm guessing laravel uses the same single point of entry routing system (as jeffrey did in this video) but much more advanced. if thats the case why does laravel work on WAMP and the tutorial codes in this video breaks on WAMP?
@@DougLopes And also mod rewrite is needed to be active, to be able to read .htaccess files, which usually is active in sharing hosting providers and some software solutions like wamp, mamp or xamp, but not in php base containers and hosting providers by using Virtual Private Server (VPS) plan.
One thing you could have done as well is to move the `parse_url` call to the `routeToController` function. This way you would only need to pass the routes as a parameter, because `$uri` is only used in the function.
The thumbnails for many of your videos look like you are starting a social club, or dating site. Just a heads up, blast from the past sort of comment ... you're teaching methods otherwise, once the video begins, are mainly spot-on
Hello I have the error no found in laragon I had to use chatgpt, in my case I had to create at root folder a file call " .htaccess " inside , FallbackResource /index.php, all request should redirect to index, also you need enable mod_rewrite in your apache config
I'm really stuck in this episode .. Whenever I click on About or Contact I am seeing this (The requested URL was not found on this server) error plz help.... I have done everything correctly,upto this point P.S. I'm using XAMPP
same here. I noticed that I can't update the uri like he did at 2:15. if you add something after 'localhost:8888/' you will get 'Not Found The requested URL /tuna was not found on this server.' but for some reason he was able to do that just fine. I am gonna try different things like googling, changing the browser or use something other than mamp.
I did things a bit differently because of the 'root level' thing. I basically copied the wordpress .htaccess file and replaced 'wordpress' in the file with the name of the project folder. I put the .htaccess file directly inside of the project folder and ofc the project folder was inside the htdocs file in mamp. Note: my project folder name was '15-make-a-php-router' The content of my .htaccess file: RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase /make-a-php-router/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /15-make-a-php-router/index.php [L]
@1:150 ish... how come your server did not respond with a 404 when you entered that jibberish url? how come all request are routed to index.php at this point? is that typical for your local server?
Answer 1 Hello just want to share how I resolved this issue, first create a .htaccess on your folder(must be a root level), then copy and paste this: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA] Answer 2 Hello I have the error no found in laragon I had to use chatgpt, in my case I had to create at root folder a file call " .htaccess " inside , FallbackResource /index.php, all request should redirect to index, also you need enable mod_rewrite in your apache config Answer 3 (mamp) I basically copied the wordpress .htaccess file and replaced 'wordpress' in the file with the name of the project folder. I put the .htaccess file directly inside of the project folder and ofc the project folder was inside the htdocs file in mamp. Note: my project folder name was '15-make-a-php-router' The content of my .htaccess file: RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase /make-a-php-router/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /15-make-a-php-router/index.php [L]
I know this is such a late question to ask but I’ll give it a try with the hopes of a follow up answer. I noticed in this video when you clicked the reload button in the browser and changed the URL-Path, all the requests were sent to a single entry point without the .htaccess file. How can I accomplish that same thing.
I did everything you did in this series, but when I did this router the home page works good ,but when I click on the other pages the browser gives me 404, idk why! 😩
Hello just want to share how I resolved this issue, first create a .htaccess on your folder(must be a root level), then copy and paste this: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
@@badal8111 This is a file that is read by the Apache server. This is used to specify certain rules that the Apache server should follow when routing. Essentially, we are saying that if the route is not referring to a file or a directory in the project, then it should refer to index.php. # This is a file that is read by the Apache server. This is used to specify certain rules that the Apache server should follow when routing. Essentially, we are saying that if the route is not referring to a file nor a directory in the project, then it should refer to index.php RewriteEngine On # Exclude existing files from the rewrite rule RewriteCond %{REQUEST_FILENAME} !-f # If previous condition is true, then exclude existing directories from the rewrite rule RewriteCond %{REQUEST_FILENAME} !-d # If previous condition is true, then redirect all other requests to index.php RewriteRule ^ index.php [QSA,L]
@@venom_21332 Thanks a lot. I did things a bit differently because of the 'root level' thing. I basically copied the wordpress .htaccess file and replaced 'wordpress' in the file with the name of the project folder. I put the .htaccess file directly inside of the project folder and ofc the project folder was inside the htdocs file in mamp. Note: my project folder name was '15-make-a-php-router' The content of my .htaccess file: RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase /make-a-php-router/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /15-make-a-php-router/index.php [L]
Sir I have a question. You are runnig the built in php web server so there is a single entry point: index.php. But on apache just gives the files that are are requested. For example: on built in php web server, demo/about will forward the request to index.php where the routing is defined. the simple router can figure out which file to require. But on apache, demo/about gives error becuase there is no file names about, instead it is about.php. the request is not passed to the index.php file which has the router. How can I solve the problem?
@@CHSKnight Answer 1 Hello just want to share how I resolved this issue, first create a .htaccess on your folder(must be a root level), then copy and paste this: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA] Answer 2 Hello I have the error no found in laragon I had to use chatgpt, in my case I had to create at root folder a file call " .htaccess " inside , FallbackResource /index.php, all request should redirect to index, also you need enable mod_rewrite in your apache config Answer 3 (mamp) I basically copied the wordpress .htaccess file and replaced 'wordpress' in the file with the name of the project folder. I put the .htaccess file directly inside of the project folder and ofc the project folder was inside the htdocs file in mamp. Note: my project folder name was '15-make-a-php-router' The content of my .htaccess file: RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase /make-a-php-router/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /15-make-a-php-router/index.php [L]
Great tuto. I have a question about different between callable Of Middleware(filters) and callable of Event Listener(hooks) Are boat the same if we use the call_user_func();
Hi Jeff, I know thiss serie is now quite a time done and I don't know if you even read this comment. But I'm no searching around for quite a long time and indeed for me who never worked in IT but wa alway interested in doing this as a hobby I am doing bad in debugging in PHP/HTML/CSS/JS... I'm more used to C, C++, Visual Basic even Assembler. It would be great if you would make a eries that explicitly teaches how to debug in Web Development! I love your little function dd() just in the beginning of this series and that i exactly what I mean! In this lesson I kinda miss a sentence about the problem when putting the require into a function: Every variable needed in any content would have to be forwarded to the function... That makes it obligatory (at least for me) to change thinking from other languages.
Single point of entry did'nt work for me. I'm using WAMP Server with php8. On my browser, if i navigate to my project folder the index.php file loads by default which is correct. From there, if i navigate to a route that doesn't exist (as jeffrey did in the begining of the video) i get a "404 The requested URL was not found on this server" error. it does not load up the default index.php file again. Is there anything i'm doing wrong? Please help
Hi, As i will do a general comment for Jeff, for he explain this, but i will try to explain. If you watched the video 2 or 3 of this series, you will see he boot up a server, but not any server, the php built in server point out to that folder, as document root. If you try with real server that comes with software solutions like XAMP, WAMP and MAMP or Docker container or on hosting provider (which usualy comes with Apache http server), this will not work, because of configurations like document root and other setup that it is needed. Ya, in his first series of PHP for beginners that he did, He did same thing and i, like you, did not understand why, which lead to more confusion to me.
@@jediampm I know laravel is much more advanced but the routing system in this tutorial looks similar to that of laravel's. Why then does laravel work on WAMP and this doesn't?
Does anyone have a simple breakdown of why this is not working on XAMPP (windows 10)? I have updated the nav partial for the `/about` path, and added the uri check in root index.php...however, whenever I click on "About" to navigate to it, I'm getting a file not found. I've been going around in circles for hours, and have tried all approaches in the comments. 😢So damn annoying too, because the root returns as normal....and up to this one video, no issues. I'm not naive, I've done my homework and tried a lot of alternatives...but I am a little green when it comes to PHP and the intricacies of it around local development. So any help would be huge! 🤜
I had to utilize the suggestion of a previous comment suggesting that an .htaccess file be created in the project's root folder with 'FallbackResource /project/index.php'. I hope this applies to your use case!
@@kazzbeast5132 Answer 1 Hello just want to share how I resolved this issue, first create a .htaccess on your folder(must be a root level), then copy and paste this: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA] Answer 2 Hello I have the error no found in laragon I had to use chatgpt, in my case I had to create at root folder a file call " .htaccess " inside , FallbackResource /index.php, all request should redirect to index, also you need enable mod_rewrite in your apache config Answer 3 (mamp) I basically copied the wordpress .htaccess file and replaced 'wordpress' in the file with the name of the project folder. I put the .htaccess file directly inside of the project folder and ofc the project folder was inside the htdocs file in mamp. Note: my project folder name was '15-make-a-php-router' The content of my .htaccess file: RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase /make-a-php-router/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /15-make-a-php-router/index.php [L]
Great Work as i have 10+ years experience in PHP, still learning alot from you and your way of teaching is awesome, I have one question when writing functions for routing why its not written in functions.php? instead have their own file, Still own file is good but functions.php means have all the functions. Can you elaborate it.
This is exactly lesson that I need.. I search this years ago, and I didn't get it.. You really know how to explain things.. Thanks a lot from the deep of my heart 🥲
Answer 1 Hello just want to share how I resolved this issue, first create a .htaccess on your folder(must be a root level), then copy and paste this: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA] Answer 2 Hello I have the error no found in laragon I had to use chatgpt, in my case I had to create at root folder a file call " .htaccess " inside , FallbackResource /index.php, all request should redirect to index, also you need enable mod_rewrite in your apache config Answer 3 (mamp) I basically copied the wordpress .htaccess file and replaced 'wordpress' in the file with the name of the project folder. I put the .htaccess file directly inside of the project folder and ofc the project folder was inside the htdocs file in mamp. Note: my project folder name was '15-make-a-php-router' The content of my .htaccess file: RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase /make-a-php-router/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /15-make-a-php-router/index.php [L]
Hi I get 404 error when i put something after the "/" in the url for example localhost/something gives me a 404 i'm using laragon How did you not got an error?
Answer 1 Hello just want to share how I resolved this issue, first create a .htaccess on your folder(must be a root level), then copy and paste this: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
Answer 2 Hello I have the error no found in laragon I had to use chatgpt, in my case I had to create at root folder a file call " .htaccess " inside , FallbackResource /index.php, all request should redirect to index, also you need enable mod_rewrite in your apache config
Answer 3 (mamp) I basically copied the wordpress .htaccess file and replaced 'wordpress' in the file with the name of the project folder. I put the .htaccess file directly inside of the project folder and ofc the project folder was inside the htdocs file in mamp. Note: my project folder name was '15-make-a-php-router' The content of my .htaccess file: RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase /make-a-php-router/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /15-make-a-php-router/index.php [L]
Thanks >>> but can you help me >>> because i have a problem running this code on windows xampp, in the comments "son of troy" suggested using htaccess file, but i don't how to do it
Answer 1 Hello just want to share how I resolved this issue, first create a .htaccess on your folder(must be a root level), then copy and paste this: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA] Answer 2 Hello I have the error no found in laragon I had to use chatgpt, in my case I had to create at root folder a file call " .htaccess " inside , FallbackResource /index.php, all request should redirect to index, also you need enable mod_rewrite in your apache config Answer 3 (mamp) I basically copied the wordpress .htaccess file and replaced 'wordpress' in the file with the name of the project folder. I put the .htaccess file directly inside of the project folder and ofc the project folder was inside the htdocs file in mamp. Note: my project folder name was '15-make-a-php-router' The content of my .htaccess file: RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase /make-a-php-router/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /15-make-a-php-router/index.php [L]
My code not work. I used your code too, but it still not works. It shows "Not Found The requested URL was not found on this server." Please solve this problem. Thanks.
Answer 1 Hello just want to share how I resolved this issue, first create a .htaccess on your folder(must be a root level), then copy and paste this: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA] Answer 2 Hello I have the error no found in laragon I had to use chatgpt, in my case I had to create at root folder a file call " .htaccess " inside , FallbackResource /index.php, all request should redirect to index, also you need enable mod_rewrite in your apache config Answer 3 (mamp) I basically copied the wordpress .htaccess file and replaced 'wordpress' in the file with the name of the project folder. I put the .htaccess file directly inside of the project folder and ofc the project folder was inside the htdocs file in mamp. Note: my project folder name was '15-make-a-php-router' The content of my .htaccess file: RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase /make-a-php-router/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /15-make-a-php-router/index.php [L]
Hi Jeff, Please explain in the next video why this works on php built in server and it will not in software solutions like XAMP, LAMP OR WAMP, Docker container or even on hosting provider. I am asking, because you did same thing your first series of php for beginners ( The PHP Practitioner), and it just confuse me a lot and i am sure others too, at that time in laracast. For example, here in youtube, you have a comment about this from Philip Tammy, to avoid more confusion and misleading people to think that make a router is simple and no need to config a server. Another think i want to ask is what is best practice for naming routes / url for full website and web api, because i worked for companies that do not how should naming the pages or routes. Thanks.
We're using PHP's built-in server for this series, so we get the rewriting for free. If you're using Apache or Nginx, the rules might be different. That's all entirely separate from the process of writing a simple PHP router. A quick Google search for something like "Apache rewrite to index.php" will provide hundreds of solutions. gist.github.com/RaVbaker/2254618 stackoverflow.com/questions/12195622/apache-redirect-directory-to-index-php
@@Laracastsofficial Hi, i know that you you using built-in server and for prod server you need mod rewrite to read the htaccess file and. htaccess file configuration for apache http server ( where all frameworks provide that kind of config file for Apache) , as i said long time ago i watched The PHP Practitioner (which was great) and i did my research for that at that time, so no need to explain to me now. To go direct to the point, in this video you should be clear, to your viewers, don't repeat same mistake of dont saying the how and why this is working. By saying or write in the comments is not enough, not all people will read the comments or make some research on it because they dont know the problem or what key words to use. And another thing, for simple projects, you dont need router to have clean urls, because like you show, if you have a file call index.php, the server know what to do, you have a folder call contact and inside you have a file call index.php or ( even index.html if it is only static page), you do '/contact/' , it will load the file. you just mention and show but dont said why should be index.php, i tell you, because exist config file that said to the server files call index.php or index.html is to load and give priority. Thanks.
@@Laracastsofficial i was very confused and frustated until i read the comments thanks jeff for the help i solved the problem by googling the solution as u told us to write
; short_open_tag ; Default Value: On ; Development Value: Off ; Production Value: Off This is what is in the php.ini file do I need to change anything?
@@ImEli2215 find or add it a bit lower down in the file without the semicolons in the beginning, what you pasted is part of Quick Reference and is not a config
Hey I have a quick question. when it comes to relative path vs absolute path, how does that affect my application? a few things to note, my file structure has the public, App dir structure. and my httpd.conf document root and directory points to the public folder by default. I have a bug that wont allow me to request the about page or contact page. I'm confused because my file and url paths are correct... but the error message is telling me the request url was not found on the server. That cant be right... I know my paths are correct. thoughts anyone...
2:21 localhost/contact does not return REQUEST_URI = "/contact" ........... why? simple - 404 The requested URL /contact was not found on this server and this happens before any php whole thing start working after: = changing apache httpd.conf, = adding corect .htaccess file in corect folder, = modifing in php code path to php files
if($uri === '/routing/index'){ require 'controllers/index.php'; }else if($uri === '/routing/contact'){ echo 'controllers/contact.php'; } I wrote this code in index.php, the route of index is working but contact is not opening on index.php. For contact I must declare contact.php then it will work, kind please help me to sort it.
Hi! I'm having trouble when we're going to implement the error pages. Chrome simply does not display the page, in this case 404.php but a standard 404 error from Chrome. I've already tried creating a .htaccess file to try and resolve it without success. Can we help me?
... TBH, i have never seen someone teach a language basics with modern dev mindset until now, definitely the best teacher
i directly came to this episode.
i was searching for "understanding routes"
u compelled me to see "previous videos also"
nice one.👍
Been writing PHP apps and websites for what feels like 20 years and I'm LOVING this series.
Jeffrey, I am a hige fan, lifetime member of Laracasts and evangelist of Laravel & Laracasts. That fake typing at the beginning almost had me spit beer on my laptop. Hahahahaha. Its awesoem how many experienced PHP guys are watching these videos here and there. Including me.
what i like is that you learn how to think like a programmer, and not only about php, althought is php for beginners. Thanks
The pace of this course and the way it's delivered is perfect for me -- and many others it seems!
This man will get me a job his teaching style is second to nobody
I'm really loving this series. I work with PHP and Javascript in my job, and I've learned everything I know about these languages just through experience and google. The basics I'm learning here is really refreshing and it's really helping me in my job, so thank you!
To be honest, before you got to parse_url function call, I thought you'd have to pull out preg_match() and thought "ooh, this is moving quickly!" haha. Nice to see the PHP devs already thought of that!
Keep up the great content!
i was thinking he would do an explode :))
HOLYY SHIITTT I LOVE YOU ❤❤❤ I'VE BEEN SEARCHING AROUND THE INTERNET FOR 5 HOURS AND THEN NOW IT'S OVER FINALLY I LOVE YOU MAAN
I love this series! A few years ago I had really trouble with understanding routing. Your first PHP series made it so clear, it was like a sudden awakening.
The other thing I enjoy here is that you try different concepts. Your first series was so object oriented, and now you have a more functional approach. Will you refactor to classes where appropiate? ;)
Also, two years ago I was about to quit web developement. But your dedication made me resist that. Your one of my favorite teachers, and also guitarist like me. All the best to you. :)
Agreed how much better is his new stuff in the past he was to fast but his new series he explains it so much better and he charges 12 pound a month you can't go wrong
Up until this point, you were teaching us MVC model without even metioning it, its just so natural.....i really love your style of teaching things, thank you !
Nice and clean as always... I was runing some tests and this behavior when you access some address that doesn't exists only works in php server. With wamp and laragon you get 404 error probably because of apache and the index.php is never called. So if you're having this issue, try just run the tutorial codes like Jeffrey in a simple "php -S localhost" and it should work.
Thank you for clearing this up for me, i had the same 404 problem earlier on wamp server. but i have one question, i'm running a laravel app on WAMP and it works, i'm guessing laravel uses the same single point of entry routing system (as jeffrey did in this video) but much more advanced. if thats the case why does laravel work on WAMP and the tutorial codes in this video breaks on WAMP?
@@Bishop_Six thats because laravel has a .htaccess on the public directory, and it make the apache redirect all requests to index.php entry
@@DougLopes And also mod rewrite is needed to be active, to be able to read .htaccess files, which usually is active in sharing hosting providers and some software solutions like wamp, mamp or xamp, but not in php base containers and hosting providers by using Virtual Private Server (VPS) plan.
@@DougLopes once again thank u very much. Now I can sleep in peace
@@jediampm thanks u very much
One thing you could have done as well is to move the `parse_url` call to the `routeToController` function. This way you would only need to pass the routes as a parameter, because `$uri` is only used in the function.
We’re not done in that file, but it’s more flexible if we instead pass in the uri.
@@Laracastsofficial are you going to cover adding variables to the URL?
I really watched it twice and now the third time. Exactly as you said :)
The thumbnails for many of your videos look like you are starting a social club, or dating site. Just a heads up, blast from the past sort of comment ... you're teaching methods otherwise, once the video begins, are mainly spot-on
Super straight forward. Nice job
Hello I have the error no found in laragon I had to use chatgpt, in my case I had to create at root folder a file call " .htaccess " inside , FallbackResource /index.php, all request should redirect to index, also you need enable mod_rewrite in your apache config
I'm really stuck in this episode ..
Whenever I click on About or Contact I am seeing this (The requested URL was not found on this server) error plz help....
I have done everything correctly,upto this point
P.S. I'm using XAMPP
I am stuck too, have you solved it?
same here. I noticed that I can't update the uri like he did at 2:15. if you add something after 'localhost:8888/' you will get 'Not Found The requested URL /tuna was not found on this server.' but for some reason he was able to do that just fine. I am gonna try different things like googling, changing the browser or use something other than mamp.
I did things a bit differently because of the 'root level' thing. I basically copied the wordpress .htaccess file and replaced 'wordpress' in the file with the name of the project folder. I put the .htaccess file directly inside of the project folder and ofc the project folder was inside the htdocs file in mamp.
Note: my project folder name was '15-make-a-php-router'
The content of my .htaccess file:
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /make-a-php-router/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /15-make-a-php-router/index.php [L]
i´m also stuck bro, could you solve it?
pffft, show me how to make a PHP interpreter in PHP
@1:150 ish... how come your server did not respond with a 404 when you entered that jibberish url? how come all request are routed to index.php at this point? is that typical for your local server?
Answer 1
Hello just want to share how I resolved this issue, first create a .htaccess on your folder(must be a root level), then copy and paste this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
Answer 2
Hello I have the error no found in laragon I had to use chatgpt, in my case I had to create at root folder a file call " .htaccess " inside , FallbackResource /index.php, all request should redirect to index, also you need enable mod_rewrite in your apache config
Answer 3 (mamp)
I basically copied the wordpress .htaccess file and replaced 'wordpress' in the file with the name of the project folder. I put the .htaccess file directly inside of the project folder and ofc the project folder was inside the htdocs file in mamp.
Note: my project folder name was '15-make-a-php-router'
The content of my .htaccess file:
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /make-a-php-router/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /15-make-a-php-router/index.php [L]
Great content by the team! 🤗🤗
I know this is such a late question to ask but I’ll give it a try with the hopes of a follow up answer. I noticed in this video when you clicked the reload button in the browser and changed the URL-Path, all the requests were sent to a single entry point without the .htaccess file. How can I accomplish that same thing.
You are doing an amazing job.
I would like to know if you share your editor's visual settings somewhere, they are great. 😍
this is phpstorm ide?
I did everything you did in this series, but when I did this router the home page works good ,but when I click on the other pages the browser gives me 404, idk why! 😩
Hello just want to share how I resolved this issue, first create a .htaccess on your folder(must be a root level), then copy and paste this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
@@venom_21332 Can You explain why and how this works?
@@venom_21332 THANK YOU!!!!!!!!!!!!!!!!!!!! You saved my life
@@badal8111 This is a file that is read by the Apache server. This is used to specify certain rules that the Apache server should follow when routing. Essentially, we are saying that if the route is not referring to a file or a directory in the project, then it should refer to index.php.
# This is a file that is read by the Apache server. This is used to specify certain rules that the Apache server should follow when routing. Essentially, we are saying that if the route is not referring to a file nor a directory in the project, then it should refer to index.php
RewriteEngine On
# Exclude existing files from the rewrite rule
RewriteCond %{REQUEST_FILENAME} !-f
# If previous condition is true, then exclude existing directories from the rewrite rule
RewriteCond %{REQUEST_FILENAME} !-d
# If previous condition is true, then redirect all other requests to index.php
RewriteRule ^ index.php [QSA,L]
@@venom_21332 Thanks a lot. I did things a bit differently because of the 'root level' thing. I basically copied the wordpress .htaccess file and replaced 'wordpress' in the file with the name of the project folder. I put the .htaccess file directly inside of the project folder and ofc the project folder was inside the htdocs file in mamp.
Note: my project folder name was '15-make-a-php-router'
The content of my .htaccess file:
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /make-a-php-router/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /15-make-a-php-router/index.php [L]
If this playlist had not ended
Very nice jeff
Sir I have a question. You are runnig the built in php web server so there is a single entry point: index.php. But on apache just gives the files that are are requested. For example: on built in php web server, demo/about will forward the request to index.php where the routing is defined. the simple router can figure out which file to require. But on apache, demo/about gives error becuase there is no file names about, instead it is about.php. the request is not passed to the index.php file which has the router. How can I solve the problem?
Im also stuck on that one
@@CHSKnight
Answer 1
Hello just want to share how I resolved this issue, first create a .htaccess on your folder(must be a root level), then copy and paste this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
Answer 2
Hello I have the error no found in laragon I had to use chatgpt, in my case I had to create at root folder a file call " .htaccess " inside , FallbackResource /index.php, all request should redirect to index, also you need enable mod_rewrite in your apache config
Answer 3 (mamp)
I basically copied the wordpress .htaccess file and replaced 'wordpress' in the file with the name of the project folder. I put the .htaccess file directly inside of the project folder and ofc the project folder was inside the htdocs file in mamp.
Note: my project folder name was '15-make-a-php-router'
The content of my .htaccess file:
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /make-a-php-router/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /15-make-a-php-router/index.php [L]
now i appreciate php thank you..
Thankyou for this episode, now I am clear how does those routers work
Young Michael Keaton is teaching some good PHP. Nice!
The code isn't fetching '/about' and '/contact' URIs. Can somebody help
Great tuto.
I have a question about different between callable Of Middleware(filters) and callable of Event Listener(hooks)
Are boat the same if we use the
call_user_func();
Hi Jeff,
I know thiss serie is now quite a time done and I don't know if you even read this comment. But I'm no searching around for quite a long time and indeed for me who never worked in IT but wa alway interested in doing this as a hobby I am doing bad in debugging in PHP/HTML/CSS/JS... I'm more used to C, C++, Visual Basic even Assembler. It would be great if you would make a eries that explicitly teaches how to debug in Web Development! I love your little function dd() just in the beginning of this series and that i exactly what I mean!
In this lesson I kinda miss a sentence about the problem when putting the require into a function: Every variable needed in any content would have to be forwarded to the function... That makes it obligatory (at least for me) to change thinking from other languages.
Single point of entry did'nt work for me. I'm using WAMP Server with php8. On my browser, if i navigate to my project folder the index.php file loads by default which is correct. From there, if i navigate to a route that doesn't exist (as jeffrey did in the begining of the video) i get a "404 The requested URL was not found on this server" error. it does not load up the default index.php file again. Is there anything i'm doing wrong? Please help
Hi,
As i will do a general comment for Jeff, for he explain this, but i will try to explain.
If you watched the video 2 or 3 of this series, you will see he boot up a server, but not any server, the php built in server point out to that folder, as document root.
If you try with real server that comes with software solutions like XAMP, WAMP and MAMP or Docker container or on hosting provider (which usualy comes with Apache http server), this will not work, because of configurations like document root and other setup that it is needed.
Ya, in his first series of PHP for beginners that he did, He did same thing and i, like you, did not understand why, which lead to more confusion to me.
@@jediampm thanks for responding. I'm using laravel on WAMP and it works out of the box. But the tutorial codes doesn't work on the same WAMP. Why?
@@jediampm I know laravel is much more advanced but the routing system in this tutorial looks similar to that of laravel's. Why then does laravel work on WAMP and this doesn't?
@@jediampm never mind, i just got the answers i needed.
If you're instead using Apache, you'll need a rewrite rule.
gist.github.com/RaVbaker/2254618
how to do it when the uri has a path parameter like /{id} ?
Does anyone have a simple breakdown of why this is not working on XAMPP (windows 10)? I have updated the nav partial for the `/about` path, and added the uri check in root index.php...however, whenever I click on "About" to navigate to it, I'm getting a file not found. I've been going around in circles for hours, and have tried all approaches in the comments.
😢So damn annoying too, because the root returns as normal....and up to this one video, no issues. I'm not naive, I've done my homework and tried a lot of alternatives...but I am a little green when it comes to PHP and the intricacies of it around local development. So any help would be huge! 🤜
I had to utilize the suggestion of a previous comment suggesting that an .htaccess file be created in the project's root folder with 'FallbackResource /project/index.php'. I hope this applies to your use case!
@@kazzbeast5132
Answer 1
Hello just want to share how I resolved this issue, first create a .htaccess on your folder(must be a root level), then copy and paste this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
Answer 2
Hello I have the error no found in laragon I had to use chatgpt, in my case I had to create at root folder a file call " .htaccess " inside , FallbackResource /index.php, all request should redirect to index, also you need enable mod_rewrite in your apache config
Answer 3 (mamp)
I basically copied the wordpress .htaccess file and replaced 'wordpress' in the file with the name of the project folder. I put the .htaccess file directly inside of the project folder and ofc the project folder was inside the htdocs file in mamp.
Note: my project folder name was '15-make-a-php-router'
The content of my .htaccess file:
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /make-a-php-router/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /15-make-a-php-router/index.php [L]
Great Work as i have 10+ years experience in PHP, still learning alot from you and your way of teaching is awesome,
I have one question when writing functions for routing why its not written in functions.php? instead have their own file, Still own file is good but functions.php means have all the functions. Can you elaborate it.
This is exactly lesson that I need.. I search this years ago, and I didn't get it..
You really know how to explain things.. Thanks a lot from the deep of my heart 🥲
Brother, Thank you so much. This process working perfectly in localhost. But not working in live server. Please help me.
Yo this is damn good man, i really feel bad why i haven't met this channel before
Anyone also have issues with routers not working on xampp? Only the index router works
Answer 1
Hello just want to share how I resolved this issue, first create a .htaccess on your folder(must be a root level), then copy and paste this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
Answer 2
Hello I have the error no found in laragon I had to use chatgpt, in my case I had to create at root folder a file call " .htaccess " inside , FallbackResource /index.php, all request should redirect to index, also you need enable mod_rewrite in your apache config
Answer 3 (mamp)
I basically copied the wordpress .htaccess file and replaced 'wordpress' in the file with the name of the project folder. I put the .htaccess file directly inside of the project folder and ofc the project folder was inside the htdocs file in mamp.
Note: my project folder name was '15-make-a-php-router'
The content of my .htaccess file:
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /make-a-php-router/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /15-make-a-php-router/index.php [L]
And I cannot seem to find the solution.
@@ImEli2215 check my other comment/comments. I found the solution
This is working in localhost, but I have problem in deploying with custom route.
cant wait for routes that have parameters in them, even if people tend to have the parameters like "id=1" as a query param
Can you make a video on Dynamic Routing? Creating pages based on JSON data?
Wouldn't this fail if I hit the page with, for example, /about/?123 ? or if the server configuration for trailing slash is enabled
I love this video. Please kindly share the video of the functions.php
what to do if i have another button in the homepage and it has another link page? pls i hope you notice it..
When I put it into the file named x, it gives an error and says it is indexing. Is there a solution? I can't use a router.
Hi
I get 404 error when i put something after the "/" in the url
for example
localhost/something
gives me a 404
i'm using laragon
How did you not got an error?
I am facing same issue.
answers of people who faced the same problem:
Answer 1
Hello just want to share how I resolved this issue, first create a .htaccess on your folder(must be a root level), then copy and paste this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
Answer 2
Hello I have the error no found in laragon I had to use chatgpt, in my case I had to create at root folder a file call " .htaccess " inside , FallbackResource /index.php, all request should redirect to index, also you need enable mod_rewrite in your apache config
Answer 3 (mamp)
I basically copied the wordpress .htaccess file and replaced 'wordpress' in the file with the name of the project folder. I put the .htaccess file directly inside of the project folder and ofc the project folder was inside the htdocs file in mamp.
Note: my project folder name was '15-make-a-php-router'
The content of my .htaccess file:
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /make-a-php-router/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /15-make-a-php-router/index.php [L]
Thanks >>> but can you help me >>> because i have a problem running this code on windows xampp, in the comments "son of troy" suggested using htaccess file, but i don't how to do it
Answer 1
Hello just want to share how I resolved this issue, first create a .htaccess on your folder(must be a root level), then copy and paste this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
Answer 2
Hello I have the error no found in laragon I had to use chatgpt, in my case I had to create at root folder a file call " .htaccess " inside , FallbackResource /index.php, all request should redirect to index, also you need enable mod_rewrite in your apache config
Answer 3 (mamp)
I basically copied the wordpress .htaccess file and replaced 'wordpress' in the file with the name of the project folder. I put the .htaccess file directly inside of the project folder and ofc the project folder was inside the htdocs file in mamp.
Note: my project folder name was '15-make-a-php-router'
The content of my .htaccess file:
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /make-a-php-router/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /15-make-a-php-router/index.php [L]
Jeffrey writes his own framework
Amazing!!
Awesome Series, but getting a 404 Not Found on Apache for /about, works great with php -S.
Really great series!
There is a problem with the router settings in xampp. If I find a solution, I will write here
Did you ever find the solution?
Thanks so much
why you cut config file .htaccess, how newbie can understand when see this video.
Thank you🙇♂️bringer of wisdom
My code not work. I used your code too, but it still not works. It shows "Not Found
The requested URL was not found on this server." Please solve this problem. Thanks.
Answer 1
Hello just want to share how I resolved this issue, first create a .htaccess on your folder(must be a root level), then copy and paste this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
Answer 2
Hello I have the error no found in laragon I had to use chatgpt, in my case I had to create at root folder a file call " .htaccess " inside , FallbackResource /index.php, all request should redirect to index, also you need enable mod_rewrite in your apache config
Answer 3 (mamp)
I basically copied the wordpress .htaccess file and replaced 'wordpress' in the file with the name of the project folder. I put the .htaccess file directly inside of the project folder and ofc the project folder was inside the htdocs file in mamp.
Note: my project folder name was '15-make-a-php-router'
The content of my .htaccess file:
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /make-a-php-router/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /15-make-a-php-router/index.php [L]
Hi Jeff,
Please explain in the next video why this works on php built in server and it will not in software solutions like XAMP, LAMP OR WAMP, Docker container or even on hosting provider.
I am asking, because you did same thing your first series of php for beginners ( The PHP Practitioner), and it just confuse me a lot and i am sure others too, at that time in laracast.
For example, here in youtube, you have a comment about this from Philip Tammy, to avoid more confusion and misleading people to think that make a router is simple and no need to config a server.
Another think i want to ask is what is best practice for naming routes / url for full website and web api, because i worked for companies that do not how should naming the pages or routes.
Thanks.
We're using PHP's built-in server for this series, so we get the rewriting for free. If you're using Apache or Nginx, the rules might be different. That's all entirely separate from the process of writing a simple PHP router.
A quick Google search for something like "Apache rewrite to index.php" will provide hundreds of solutions.
gist.github.com/RaVbaker/2254618
stackoverflow.com/questions/12195622/apache-redirect-directory-to-index-php
@@Laracastsofficial Hi, i know that you you using built-in server and for prod server you need mod rewrite to read the htaccess file and. htaccess file configuration for apache http server ( where all frameworks provide that kind of config file for Apache) , as i said long time ago i watched The PHP Practitioner (which was great) and i did my research for that at that time, so no need to explain to me now.
To go direct to the point, in this video you should be clear, to your viewers, don't repeat same mistake of dont saying the how and why this is working. By saying or write in the comments is not enough, not all people will read the comments or make some research on it because they dont know the problem or what key words to use.
And another thing, for simple projects, you dont need router to have clean urls, because like you show, if you have a file call index.php, the server know what to do, you have a folder call contact and inside you have a file call index.php or ( even index.html if it is only static page), you do '/contact/' , it will load the file. you just mention and show but dont said why should be index.php, i tell you, because exist config file that said to the server files call index.php or index.html is to load and give priority.
Thanks.
@@Laracastsofficial i was very confused and frustated until i read the comments thanks jeff for the help i solved the problem by googling the solution as u told us to write
thanks man, I confused too. I had re-installed xampp in my PC, but still doesn't work. Using PHP's build-in server is the answer.
Im having the same f* problem, still can’t solve it.
How do u use php-built in server?
Would it affect my xamp config?
To all xammp users, short open tag
; short_open_tag
; Default Value: On
; Development Value: Off
; Production Value: Off
This is what is in the php.ini file do I need to change anything?
@@ImEli2215 find or add it a bit lower down in the file without the semicolons in the beginning, what you pasted is part of Quick Reference and is not a config
@@and-why Ow ok let me try that out and see if it works.
what is the name of this ide ?
plz let me know
Amazing 🔥👑
anybody who's wondering why their routing doesn't work , look for the answers in the comments
I am facing this issue.
PHP is the best
please share editor, looking best!
ITS REALLY WORKED LOL THANK YOU DUDE
@1:52 Why are you not getting a 404 not found?😕
I found a solution. I had to add a redirect all in IIS web.config.
for some reason its not working for me
1:42 General Kenobi!
Thank you!
Can you teach SOLID PRINCIPLE in php please
thanks for video
great tut! thx!
The real question is how do I create product pages without GET Params. This would look much better
PHP For Beginners from master :D
this will not work if you running in apache service he running it from php server php -S it will work but in apache you need to use .htaccess
I am facing this issue. How can I solve this? Can you explain it please?
Wow!
👍
Hey I have a quick question. when it comes to relative path vs absolute path, how does that affect my application? a few things to note, my file structure has the public, App dir structure. and my httpd.conf document root and directory points to the public folder by default. I have a bug that wont allow me to request the about page or contact page. I'm confused because my file and url paths are correct... but the error message is telling me the request url was not found on the server. That cant be right... I know my paths are correct. thoughts anyone...
Use the server by PHP, you can use: php -S localhost:8888 in the console
nic cool😍
*in the last episode we learn how to die* 1:57
theme
5:28
This is not for beginners, you lost me after 2 minutes and I am not a beginner. You go way too fast and don't explain, you just show things.
2:21 localhost/contact does not return REQUEST_URI = "/contact" ........... why? simple - 404 The requested URL /contact was not found on this server and this happens before any php
whole thing start working after: = changing apache httpd.conf, = adding corect .htaccess file in corect folder, = modifing in php code path to php files
I am facing same issue
$uri = parse_url($_SERVER['REQUEST_URI'])['path'];
if($uri === '/routing/index'){
require 'controllers/index.php';
}else if($uri === '/routing/contact'){
echo 'controllers/contact.php';
}
I wrote this code in index.php, the route of index is working but contact is not opening on index.php. For contact I must declare contact.php then it will work, kind please help me to sort it.
Excellent lesson!!!!
Hi! I'm having trouble when we're going to implement the error pages. Chrome simply does not display the page, in this case 404.php but a standard 404 error from Chrome. I've already tried creating a .htaccess file to try and resolve it without success. Can we help me?