...

/

Create a Router for our Project

Create a Router for our Project

Redirect HTTP calls to “index.php” with the help of the “.htaccess” file.

We won’t be creating something sophisticated here, just a basic routing system for our application.

In a nutshell, we’ll:

  • Redirect all the HTTP requests to index.php (the router).
  • Create a routing system with switch.

Redirect all the HTTP requests to the router

We have an index.php file at the root of our application. We’ll use it as our router.

Let’s create a .htaccess file in the root of the project and redirect all the traffic to index.php:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php 

In our ...