Web server

While the documents, examples and the administrator tool come with configs for the Apache web-server directory configs inside .htaccess files, Artaengine application can works with other web servers too. This tutorial describes how to set the web-server.

The thing is that you have to set the web-server to send (re write) all the requests to one PHP file which starts Artaengine. After that Artaengine will take care of the requests and will do the routing, dispatching, mapping URLs to factory or whatever you call it. But you have to also tell the web server to exclude requests to static files such as JavaScript, CSS, images, etc.

In apache you can put a config like this inside the .htaccess file or under <directory /var/www/app>:

    Options +FollowSymlinks
    RewriteEngine on

    RewriteRule robots.txt robots.txt [L]

    RewriteRule ^images/(.+)$ browser/resources/images/$1 [L]
    RewriteRule ^css/(.+)$ browser/resources/css/$1 [L]
    RewriteRule ^js/(.+)$ browser/resources/js/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !^(.*)\.(ico|jpg|png|js|css|swf|xml|txt)$
    RewriteRule ^ start.php [L]

In this example all requests which are not to specific file types will go to start.php. The static file physical address differs from the URLs which is a good thing. Artaengine can find out the path in the URL but you can also mark the path for Aartaengine by config it to a parameter in the URL query-string. By default this parameter is "q" you can change this parameter by editing /arta/libs/RequestUrl.php and changing the value of const PATH_KEY = 'q';

    Options +FollowSymlinks
    RewriteEngine on

    RewriteRule robots.txt robots.txt [L]

    RewriteRule ^images/(.+)$ browser/resources/images/$1 [L]
    RewriteRule ^css/(.+)$ browser/resources/css/$1 [L]
    RewriteRule ^js/(.+)$ browser/resources/js/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !^(.*)\.(ico|jpg|png|js|css|swf|xml|txt)$
    RewriteRule ^(.*)$ start.php?q=$1 [L,QSA]

If your version of Apache supports [END] this is a more simple and efficient way"

    Options +FollowSymlinks
    RewriteEngine on

    RewriteRule robots.txt robots.txt [L]

    RewriteRule ^images/(.+)$ browser/resources/images/$1 [END]
    RewriteRule ^css/(.+)$ browser/resources/css/$1 [END]
    RewriteRule ^js/(.+)$ browser/resources/js/$1 [END]

    RewriteRule ^ start.php [END]

You may want to add a fake path to the URL which is ignored when rewritten to the physical directory. This is useful to update the cached resource files on client browsers by adding a path which changes with every build. Because the path is fake you do not have to do anything. Artaengine can add the build version to the resource URLs see and a rewrite rule like below can ignore it:

    Options +FollowSymlinks
    RewriteEngine on

    RewriteRule robots.txt robots.txt [L]

    RewriteRule ^images/(.+)$ browser/resources/images/$1 [L]
    RewriteRule ^(.*/)?css/(.+)$ browser/resources/css/$2 [L]
    RewriteRule ^(.*/)?js/(.+)$ browser/resources/js/$2 [L]

    RewriteCond %{REQUEST_FILENAME} !^(.*)\.(ico|jpg|png|js|css|swf|xml|txt)$
    RewriteRule ^ start.php [L]

Using this basics you can setup any other web server to work in the same way. For example config up nginx can be even easier by using something like this:

    location /js/ {
        alias /var/www/app-dir/browser/resources/js/
    }
    location /css/ {
        alias /var/www/app-dir/browser/resources/css/
    }
    location /images/ {
        alias /var/www/app-dir/browser/resources/images/
    }
    location / {
        rewrite ^ /start.php
    }
TOP