Routing without a framework in PHP

I am having trouble finding out how to do routing with PHP.

I know WordPress and Laravel use it, but I was wondering how to code it.

I realize it would use Apache mod rewrite, but I'm having trouble figuring out how to do routing without a framework in PHP.
burnedfacelessAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Zakaria AcharkiAnalyst DeveloperCommented:
It will be always better to use a framework or a library like "PHP-Router", but if you want to make your own routing you could take a look at :

https://www.taniarascia.com/the-simplest-php-router/
https://thewebtier.com/php/create-your-own-php-router-the-simplest-possible-way/

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Routing means different things to different people.

I'm guessing your describing transforming a link from one form to another, as in a normal redirect request.

If this is correct, then routing is always best done at the Apache level, with rewrite rules... because... it's less over head, as there's no PHP involvement. Handling redirects at the PHP level is far more resource intensive than at the Apache level.

Maybe provide an example of what exactly you mean by routing + people can provide better comments.

Note: If you are talking about redirects, always be sure to use 302 redirects, rather than 301 redirects, because 301 redirects cache in all browsers forever, so if you make a typo or like to change your entire site layout sometime in the future, using 301s will make this complex or impossible... depending on your site rework...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Laravel

From novice to tech pro — start learning today.