I know you can add rules in htaccess, but I found that PHP frameworks don't do that and somehow you still have beautiful URLs. How can servers do this if they don't know the URL rules?
I've been looking for 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 the following rules:
The file then compares the request(
$_SERVER["REQUEST_URI"]
) with a list of routes - patterns that match the request to a controller action (in an MVC application) or other actions Map execution paths. Frameworks often include a route that can infer controllers and actions from the request itself, as a backup route.A simple example:
In conjunction with the first configuration, this is a simple script that allows you to use URLs like
domain.com/about
. Hope this helps you understand what's going on here.