Route URL Rewriting

We strongly encourage you to use a web server that supports URL rewriting; this will let you enjoy clean, human-friendly URLs with your Yee application out of the box. To enable URL rewriting, you should use the appropriate tools provided by your web server to forward all HTTP requests to the PHP file in which you instantiate and run your Yee application. The following are sample, bare minimum, configurations for Apache with mod_php and nginx. These are not meant to be production ready configurations but should be enough to get you up and running.

Apache and mod_rewrite

Here is an example directory structure:

    public_html/ <-- Document root!
        index.php <-- I instantiate Yee here!
        Yee/ <-- We can store Yee lib files here!

The .htaccess file in the directory structure above contains:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

You also need a directory directive to enable .htaccess files and allow the RewriteEngine directive to be used. This is sometimes done globally in the httpd.conf file, but its generally a good idea to limit the directive to just your virtual host by enclosing it in your VirtualHost configuration block. This is generally setup in your configuration in the form of:

<VirtualHost *:80>
    DocumentRoot "/path/"

    #ErrorLog "logs/"
    #CustomLog "logs/" combined

    <Directory "/path/">
        AllowOverride All
        Order allow,deny
        Allow from all

As a result, Apache will send all requests for non-existent files to our index.php script in which we instantiate and run our Yee application. With URL rewriting enabled and assuming the following Yee application is defined in index.php, you can access the application route below at “/foo” rather than “/index.php/foo”.

$app = new \Yee\Yee();
$app->get('/foo', function () {
    echo "Foo!";


We will use the same example directory structure as before, but with nginx our configuration will go into nginx.conf.

    public_html/ <-- Document root!
        index.php <-- We instantiate Yee here!
        Yee/ <-- We store Yee lib files here!

Here is a snippet of a nginx.conf in which we use the try_files directive to serve the file if it exists, good for static files (images, css, js etc), and otherwise forward it on to the index.php file.

server {
    listen       80;
    root         /path/;

    try_files $uri /index.php;

    # this will only pass index.php to the fastcgi process which is generally safer but
    # assumes the whole site is run via Yee.
    location /index.php {
        fastcgi_connect_timeout 3s;     # default of 60s is just too long
        fastcgi_read_timeout 10s;       # default of 60s is just too long
        include fastcgi_params;
        fastcgi_pass;    # assumes you are running php-fpm locally on port 9000

Most installations will have a default fastcgi_params file setup that you can just include as shown above. Some configurations don’t include the SCRIPT_FILENAME parameter. You must ensure you include this parameter otherwise you might end up with a "No input file specified" error from the fastcgi process. This can be done directly in the location block or simply added to the fastcgi_params file. Either way it looks like this:

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

Without URL Rewriting

Yee will work without URL rewriting. In this scenario, you must include the name of the PHP file in which you instantiate and run the Yee application in the resource URI. For example, assume the following Yee application is defined in index.php at the top level of your virtual host’s document root:

$app = new \Yee\Yee();
$app->get('/foo', function () {
    echo "Foo!";

You can access the defined route at “/index.php/foo”. If the same application is instead defined in index.php inside of the physical subdirectory blog/, you can access the defined route at /blog/index.php/foo.