Redirect Setup for Thrive Tracker

Thrive Tracker requires URL rewriting to allow the user interface to function and various backend functions to work correctly. This rewrite will take addresses such as /ajax/campaigns/getGeneral/123456 and direct the traffic to the AJAX controller which will in turn direct the request to the appropriate set of functions. This method makes the application significantly more flexible and less error prone.

Thrive Tracker also employs rewrite rules to prevent un-authorized access to the reports and log files that are generated. These particular rewrite rules are placed on the /app/exports, /app/logs, /app/reports, /app/templates folders. The rewrite rule simply diverts all traffic to the index.php page in the respective folders. From there the index.php controls the access to the files in the folders.

Most standard installations of web servers such as Apache and NGINX come with rewrite engines pre-setup. This makes it so the user only needs to do simple configurations based on the specific application being used.

Thrive Tracker comes with the file required for the Apache rewrite. So as long as the rewrite engine is enabled, there should be nothing you need to do. For more information about the Apache setup, please see the Apache section below.

NGINX is growing in popularity for high traffic web servers because of specific advantages with how the requests are handled. Thrive Tracker has been tested with NGINX to confirm functionality. Since Thrive Tracker is entirely a PHP application, PHP must be setup to run under NGINX. For our test setup we use the FastCGI process manager, PHP-FPM. For more information about the NGINX setup, please see the NGINX section below.

We have included a test function with the application in the hopes that problems with the installation can be found prior to completing the setup. This test, and others, can be found in your installation at /app/install/check.php. In order for the test to be performed, the database must already be setup in Step 1 since the test requires the installation URL. The test is automatically performed at the beginning of Step 2, so if you do not receive a warning about a problem, you should be good to go.

NGINX

The rewrite rule that we tested with is specific to the AJAX controller. There might be a way to do this in a generic method, but this is the setup that we have tested. NGINX uses either a single configuration file, or a set of files. These rules go into one of those configuration file. This is contrary to the Apache setup that uses files in the parent folder of the rewrite. The basic rule is:

location /ajax {
    try_files  $uri  $uri/  /ajax/controller.php?$query_string;
}

This rule goes inside the server declaration. The location is relative to the server root. So if you are installing Thrive Tracker into a subdirectory, the path will include the subdirectory like:

location /t/ajax {
    try_files  $uri  $uri/  /t/ajax/controller.php?$query_string;
}

We have tested the installation as both the default and virtual server. In both cases, the rule was unchanged as long as the paths are correct.

While it is not required to make the application work, we highly recommend adding the redirect rules for the /app/exports, /app/logs, /app/reports, /app/templates folders. The rules for these folder simply needs to redirect all traffic to the index.php script.

location /app/exports {
    rewrite ^ /app/exports/index.php last;
}
location /app/logs {
    rewrite ^ /app/logs/index.php last;
}
location /app/reports {
    rewrite ^ /app/reports/index.php last;
}
location /app/templates {
    rewrite ^ /app/templates/index.php last;
}

Apache

Thrive Tracker comes with .htaccess files that are located in the /ajax, /app/exports, /app/logs, /app/reports, /app/templates folders. Most Apache installations allow these file to change how the server acts in their respective folders. The setting that allows the .htaccess file to work is AllowOverride All.

If your Apache installation does not allow .htaccess files, you can place the contents of the file into your configuration file for the server in a Directory directive. As an example:

<Directory "/opt/bitnami/apps/thrive/public_html/ajax">
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ controller.php [L]
    </IfModule>
</Directory>

While it is not required to make the application work, we highly recommend doing this for the /app/exports, /app/logs, /app/reports, /app/templates folders.

<Directory "/opt/bitnami/apps/thrive/public_html/app/exports">
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteRule ^ index.php [L]
    </IfModule>
</Directory>
<Directory "/opt/bitnami/apps/thrive/public_html/app/logs">
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteRule ^ index.php [L]
    </IfModule>
</Directory>
<Directory "/opt/bitnami/apps/thrive/public_html/app/reports">
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteRule ^ index.php [L]
    </IfModule>
</Directory>
<Directory "/opt/bitnami/apps/thrive/public_html/app/templates">
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteRule ^ index.php [L]
    </IfModule>
</Directory>