The Front Controller Pattern PHP

It is a controller that handles all requests, you need to have a single part of your website that is fully responsible for handling all incoming requests to your site, “a single entry point”. This is usuall done by pointing all requests to a single PHP file, usually index.php. The request is forwarded to the appropriate controller action by matching the URL path, it sees every page as the same script..

A disadvantage to this pattern is the complexity of the Front Controller, which may have to manage the Dependency Injection and autoloading of the various views and/or controllers, “if your files are loaded by controller actions” on every request. The front controller pattern is a specialized kind of mediator pattern

Implementing the front controller pattern.

.htaccess


# Redirect to the front controller
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^page/([a-z]*)$ ./index.php?page=$1

turns
site.com/index.php?page=one
site.com/page/one

index.php