Routing: Mapping URLs
Learn how to create a simple PHP router.
We'll cover the following...
We'll cover the following...
Purpose of routing
Another important concept that needs to be discussed before we move on to the next chapter is routing. We will be discussing it because of the following two concerns:
- We have
.phpin every page URL, which does not look great. A URL that looks like/picturesinstead of/pictures.phpneeds to be used. - The URL of a page is tied to its file name, which does not give us flexibility. A URL that looks like
/random-number, which shows the output of therandom.phpscript, needs to be used. We also want to be able to rename that file, while the URL stays the same and vice versa ( we should be able to change the URL without changing the name of the script).