5.6. Base URL and subdirectories

Unlike the original Router, RewriteRouter can be used in subdirectories - it automatically detects your base URL and sets it accordingly. For example: if you keep your index.php in a webserver subdirectory named /projects/myapp/index.php rewrite base (base URL) will be set to /projects/myapp. This string will then be stripped from the beginning of the path before calculating any route matches. This frees one from the necessity of prepending it to any of your routes. The route of 'user/:username' will match URIs like http://localhost/projects/myapp/user/martel and http://example.com/user/martel.

[Note] Note
Automatic rewrite base is case sensitive, so make sure your URL will match a subdirectory name in a filesystem (even on Windows machines). If it doesn't you will get to noRoute action.

Should rewrite base be detected incorrectly you can override it with your own base path with the help of the setRewriteBase method of the RewriteRouter class:

$router->setRewriteBase('/projects/myapp');
[Note] Note
This step won't be necessary in most cases and is strongly discouraged as it introduces another configuration variable which would have to be altered when one moves code to another directory configuration.