Site Replication and subdomains

NOTE: This article is only and exclusively for standalone (self-hosted) Post Affiliate Pro (Network)
Few customers asked how to achieve subdomain replication for affiliates. They wanted to allow affiliates to use https://abcdefg.domain.com/ instead of https://www.domain.com/site/abcdefg ...

With our feature of Site Replication, you can achieve nice looking URL instead of ordinary long links, but modifying it into subdomain version needs a lot of work to do. It is not just a setting, you have to do exact steps otherwise it can not work.

Description
What we are going to explain here would change your ordinary links from something like this:
https://www.yoursite.com/?a_aid=testaff
into links with affiliate subdomain, e.g.:
https://testaff.yoursite.com/

To achieve something like this, you need server that runs Apache with mod_rewrite module.

Configuration
First of all you have to prepare your server to accept subdomains. You have to create so called "wildcard" DNS A record in your DNS zone pointing to your domain IP. The wildcard DNS record is a record represented by an asterisk sign "*". This will work for all non-existing subdomains so e.g. *.yoursite.com will match testaff.yoursite.com; aff123.yoursite.com etc...
(If you do not understand these steps, please contact your hosting to help you with this)

The next step in the configuration is server aliasing. You have to configure your Apache server to serve the pages that come for any subdomain of your domain. You have to do it by adding a wildcard ServerAlias.
Add the following line to httpd.conf VirtualHosts section for your domain
:
ServerAlias www.yoursite.com yoursite.com *.yoursite.com
(please contact your hosting to help you with this in case you do not have permissions to do this)

Modification of your .htaccess
Post Affiliate Pro 4 generates a special .htaccess file for your Replicated sites. In case you are following this scenario you will need to manually change the .htaccess code as there is a special approach to your replication.

Your .htaccess file have to contain these lines:
Options +FollowSymLinks
RewriteEngine On
If your Post Affiliate Pro 4 is installed in root, use this line: 
RewriteBase /
If your Post Affiliate Pro 4 is installed in a special directory, e.g. /affiliate, use this line:
RewriteBase /affiliate/
Next lines are as follows:
RewriteCond %{HTTP_HOST} !www.yoursite.com$ [NC]

RewriteCond %{HTTP_HOST} ^(www.)?([a-zA-Z0-9-]+).yoursite.com [NC]

RewriteRule (.*) scripts/page.php?a_aid=%2&a_bid=11111111&a_file=$1 [L,QSA]
The first line tells the server to ignore your original www domain to prevent redirecting. You have to add the similar line for each of your existing subdomains if you do not want them to be redirected. E.g. if you already have a shopping cart at a subdomain "cart" then you have to add this line:
RewriteCond %{HTTP_HOST} !cart.yoursite.com$ [NC]
You can see 11111111 in the third line, just after "a_bid=". You have to change this value to the actual ID of your created site replication banner. You can find this banner ID in your Post Affiliate Pro merchant panel: banners->banners manager->edit your site replication banner there. The actual ID of the banner can be seen in header right below the banner name:


based on the example screenshot above the third line should look like this:
RewriteRule (.*) scripts/page.php?a_aid=%2&a_bid=2063145c&a_file=$1 [L,QSA]

So the final htaccess code from our example case (let's say the application is installed in /affiliate directory) looks like this:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /affiliate/

RewriteCond %{HTTP_HOST} !www.yoursite.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-zA-Z0-9-]+).yoursite.com [NC]
RewriteRule (.*) scripts/page.php?a_aid=%2&a_bid=2063145c&a_file=$1 [L,QSA]
×