I know that you can add rules in htaccess, but I see that PHP frameworks don’t do that and somehow you still have pretty URLs. How do they do that if the server is not aware of the URL rules?
I’ve been looking Yii’s url manager class but I don’t understand how it does it.
This is usually done by routing all requests to a single entry point (a file that executes different code based on the request) with a rule like:
This file then compares the request (
$_SERVER["REQUEST_URI"]) against a list of routes – a mapping of a pattern matching the request to a controller action (in MVC applications) or another path of execution. Frameworks often include a route that can infer the controller and action from the request itself, as a backup route.A small, simplified example:
Combined with the first configuration, this is a simple script that will allow you to use URLs like
domain.com/about. Hope this helps you make sense of what’s going on here.