Generate Captive Portals

This is a quick tutorial on how to generate captive portal pages on Apache web servers.

Step 01: On /var/www/html/ create a file named index.html with your captive portal username and password fields.

Step 02: Then, on the pc where Apache is running, migrate to /etc/apache2/sites-enabled/ and edit a filename called 000-default.conf

Step 03: Place the following lines on the end of 000-default.conf


<Directory "/var/www/html">
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ / [L,QSA]
</Directory>

view raw

Description: There's not much to describe here. There's been use of some clear regular expressions to replace every page starting with anything(^.*) to the captive portal page(index.html) on establishing connection.

Step 04: Then restart apache2 service, and you're all set.

Note: The Rewrite* depends on a plugin called rewrite and in most cases this plugin is disabled by default, so to enable it you'd have to type in from the shell the following command as root;


# a2enmod rewrite

view raw

Made with <3 by samiuljoy

rss | about | go to top