Installation with NGINX (rewrite rules)

Since version 5+ Post Affiliate Pro stores all templates, images, CSS files in database instead of directly in file system.

In order to keep the link structure untouched (backward compatibility reasons) we have added a few rules to .htaccess files which redirect requests to correct files which load the requested resources from DB.

Also since version 5.4.24.3 we have added an extra option to hash names of tracking scripts which will work only in case of correctly working .htaccess files.

Since NGINX doesn't support .htaccess files you have to add the rewrite rules from the following 2 files to your NGINX configuration:

/.htaccess
/scripts/.htaccess
(responsible for hashing of tracking scripts)
/api/v2/.htaccess

Current .htaccess rules are:

<ifmodule mod_rewrite.c>

RewriteEngine on

#replicated sites
RewriteRule ^sites/([^/]+)/([^/]+)/(.*) scripts/page.php?a_aid=$2&a_bid=$1&a_file=$3 [L,QSA]
RewriteRule ^sites/([^/]+)/*(.*) scripts/page.php?a_aid=$2&a_bid=$1&a_redir=Y [L,QSA]
RewriteRule ^accounts/default1/files/(.*) scripts/file.php?file=files/$1 [L,QSA]
RewriteRule ^accounts/default1/banners/(.*) scripts/file.php?file=banners/$1 [L,QSA]

#accessing non-tpl theme files
RewriteRule ^accounts/default1/themes/(.*) scripts/file.php?file=themes/$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^accounts/default1/[^/]*[b]{1}[^/]*/(.*) scripts/file.php?file=banners/$1 [L,QSA]

</ifmodule>

and from the second file located in /scripts folder:

<ifModule mod_rewrite.c>

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^[^/]*\.swf pap.swf [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^[^/]*[r]{1}[^/]*$ track.php [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^[^/]*[c]{1}[^/]*$ click.php [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^[^/]*[j]{1}[^/]*$ trackjs.js [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^[^/]*[p]{1}[^/]*$ trackjs.php [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^[^/]*[s]{1}[^/]*$ sale.php [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^[^/]*[i]{1}[^/]*$ imp.php [L,QSA]

</ifModule>

These rules have to be converted to NGINX rules (we have used converter https://winginx.com/en/htaccess).

The converted rules for NGINX configuration file would look something like this ( do NOT forget to change the highlighted parts) :

server {
        listen   80;

        server_name www.YOURDOMAINNAME.com;

        error_log /var/log/nginx/YOURDOMAINNAME-error.log;

        root /PATH_TO_YOUR_PAP;
        index index.php index.html index.htm;

        location ~ ^/site/ {
                try_files $uri $uri/ /site/index.php?$uri&$args;
                break;
        }

        # New PAP Nginx rules
        location ~ ^/sites/ {
                rewrite ^/sites/([^/]+)/([^/]+)/(.*) /scripts/page.php?a_aid=$2&a_bid=$1&a_file=$3 last;
                rewrite ^/sites/([^/]+)/*(.*) /scripts/page.php?a_aid=$2&a_bid=$1&a_redir=Y last;
        }

        location ~ ^/accounts/ {
                rewrite ^/accounts/default1/files/(.*) /scripts/file.php?file=files/$1 last;
                rewrite ^/accounts/default1/banners/(.*) /scripts/file.php?file=banners/$1 last;
                rewrite ^/accounts/default1/themes/(.*) /scripts/file.php?file=themes/$1 last;
                if (!-e $request_filename){
                     rewrite "^/accounts/default1/[^/]*[b]{1}[^/]*/(.*)" /scripts/file.php?file=banners/$1 last;
                } 
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                include fastcgi_params;
        }

        location ~ \.css {
                add_header Content-Type text/css;
        }

        location ~ /scripts/ {
                if (!-e $request_filename){
                        rewrite "^/scripts/[^/]*\.swf" /scripts/pap.swf last;
                        rewrite "^/scripts/[^/]*[r]{1}[^/]*$" /scripts/track.php last;
                        rewrite "^/scripts/[^/]*[c]{1}[^/]*$" /scripts/click.php last;
                        rewrite "^/scripts/[^/]*[j]{1}[^/]*$" /scripts/trackjs.js last;
                        rewrite "^/scripts/[^/]*[p]{1}[^/]*$" /scripts/trackjs.php last;
                        rewrite "^/scripts/[^/]*[s]{1}[^/]*$" /scripts/sale.php last;
                        rewrite "^/scripts/[^/]*[i]{1}[^/]*$" /scripts/imp.php last;
                }
        }

        location ~ /api/v2/ {
                if (!-e $request_filename){
                        rewrite ^(.*)$ /api/v2/index.php last;
                }
        }
}

There are 2 special directives in the code above:

location ~ \.php - NGINX adds its own Content-type header instead of the one our php scripts set for image headers. To prevent this change of Content-type header we also needed to add this exception in NGINX rule.

location ~ \.css - On some NGINX servers CSS files were not loaded correctly due to strict checking of MIME types so we had to add also this directive to configuration to ensure that all CSS files are loaded as text/css.

 

Finally, do not forget to reload your server configuration to apply the changes. It should be enough to reload it using console "service nginx reload" command, however if that did not help, try restarting it.

×