Placing Forced Ads On Your Customers' Web Sites With .htaccess (ISPConfig)

Want to support HowtoForge? Become a subscriber!
 
Submitted by grandpagenocide (Contact Author) (Forums) on Fri, 2008-04-11 13:32. :: Other

Placing Forced Ads On Your Customers' Web Sites With .htaccess (ISPConfig)

I wrote this howto for those who want to place forced ads on their ISPConfig server. Probably you can set up forced ads in different ways but I found the way descibed here.

I am using Debian Etch and ISPConfig 2.2.19 in this example.

What needs to be done:

  • edit apache config
  • create .htaccess files
  • create header and footer with ads
  • disable the ads on accounts that upgrade

I had to enable PHP server wide for this to work, and since I give all my clients PHP, it is not a big deal, but if anyone can update this with a method to only allow PHP in the /var/www and /var/www/ads directories that would be appreciated.

Let’s show where our ISPConfig server is capable of, here we go:

 

Step 1: Enable PHP System Wide

vi /etc/mime.types

Uncomment the following lines:

[...]
#application/x-httpd-php phtml pht php
#application/x-httpd-php-source phps
#application/x-httpd-php3 php3
#application/x-httpd-php3-preprocessed php3p
#application/x-httpd-php4 php4
[...]

vi /etc/apache2/mods-enabled/php5.conf

Uncomment the AddType lines:

<IfModule mod_php5.c>
# AddType application/x-httpd-php .php .phtml .php3
# AddType application/x-httpd-php-source .phps
</IfModule>

 

Step 2

First let's edit the Apache configuration:

vi /etc/apache2/apache2.conf

Towards the bottom of the apache2.conf you will find:

<Directory /var/www/sharedip>
Options +Includes -Indexes
AllowOverride None
AllowOverride Indexes AuthConfig Limit FileInfo
Order allow,deny
Allow from all
<Files ~ "^\.ht">
Deny from all
</Files>
</Directory>

Immeidately after that add:

<Directory /var/www>
Options +Includes -Indexes
AllowOverride None
AllowOverride Indexes AuthConfig Limit FileInfo Options
Order allow,deny
Allow from all
<Files ~ "^\.ht">
Deny from all
</Files>
</Directory>

Below that you will find:

<Directory /var/www/*/web>
Options +Includes -Indexes
AllowOverride None
AllowOverride Indexes AuthConfig Limit FileInfo
Order allow,deny
Allow from all
<Files ~ "^\.ht">
Deny from all
</Files>
</Directory>

Change this to:

<Directory /var/www/*/web>
Options +Includes -Indexes
AllowOverride None
AllowOverride Indexes AuthConfig Limit FileInfo Options
Order allow,deny
Allow from all
<Files ~ "^\.ht">
Allow from root
Deny from all
</Files>
</Directory>

Save and:

/etc/init.d/apache2 restart

 

Step 3

Now let's create a directory:

mkdir /var/www/ads

 

Step 4

We are going to create two PHP files now. Let's make footer.php with your footer ad and let's make blank.php that is actually blank.

 

Step 5: Creating .htaccess File

Use any text editor you like; most of them will give you another extention, but rename the file to .htaccess and have it contain the following:

php_value output_buffering 4098
AddType application/x-httpd-php htm
AddType application/x-httpd-php html
php_value auto_append_file '/var/www/ads/footer.php'

And that's it, now every site on the server will have your forced footer, the same goes if you want a header.

 

To Disable Ads On An Individual Site

Create another .htaccess file with the following contents:

php_value output_buffering 4098
AddType application/x-httpd-php htm
AddType application/x-httpd-php html
php_value auto_append_file '/var/www/ads/blank.php'

and place it in the /web directory of that site.

And that's it guys, you now have forced ads.


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Anonymous (not registered) on Sat, 2012-05-26 07:25.
Ubuntu 11.10 and ispconfig 3 and fail to make it work! Can you help? Please help me!
Submitted by Noahsarkz (not registered) on Thu, 2009-07-16 06:25.
     This is really a nice idea.......im wondering if this could be implemented on a site by site basis depending on the hosting package a client chooses by utilizing the apache directive field option on the sites control panel....you could pick and choose who got forced adds....sweet idea i really enjoyed and appreciated this post....Noahsarkz
Submitted by Petros (not registered) on Tue, 2009-02-17 01:44.
Doing this will make html and htm files be parsed as PHP files. This can cause some unnecessary errors or vulnerabilities on poorly designed scripts.
Submitted by mastrboy (registered user) on Fri, 2008-04-11 17:06.
this is evil! don't force ads on people!
Submitted by IncomingFire (registered user) on Sat, 2008-04-12 15:52.

No I don't think its evil.  Especially if you are providing free hosting to someone and the advertisement is at the bottom of the page and most visitors to sites don't scroll past the first page of content anyways....

So no, not evil.  A way of ofsetting the costs of providing a free service to someone.

Submitted by grandpagenocide (registered user) on Thu, 2008-08-07 05:16.
incomingfire, thanks for the defense :) although the comments are old i have been MIA for a while, but reality is that if your offering free hosting, there has to be a limit or there has to be a way to recoup for offering free hosting, I currently have approximately 500 sites that have free hosting with my service. If i didnt put ads on them they just wouldnt be equitable for me to offer free hosting
Submitted by gobokster (not registered) on Tue, 2008-12-16 10:09.
i tried this with the ISPConfig 2.2.28 and unfortunately it's not running .. any others tips that i can turn this things around