Installation

Get the files

The repository contains a subfolder public_html. Run git clone or extract the downloaded archive 1 level above webroot.

In this example the software will be installed into a webroot /var/www/links/public_html:

mkdir /var/www/
git clone https://git-repo.iml.unibe.ch/iml-open-source/redirect-handler.git links

The document root of the web must point to the public_html directory. The config folder is outside the webroot.

.
├── config
│   ├── aliases.json.dist
│   └── redirects_domain.example.com.json.dist
├── docs
│   ├── ...
|   └── ... 
├── public_html
│   ├── admin.php
│   ├── classes
│   │   ├── redirect.admin.class.php
│   │   ├── redirect.admin.class.php_enabled.txt.dist
│   │   └── redirect.class.php
│   └── index.php
└── readme.md

Webserver

This is the basic idea how it works:

  • Create on or multiple vhosts with document root /var/www/links/public_html
  • optional: one extra domain eg. links.example.com points to /var/www/links/public_html too - and is restricted with ip restriction, basic auth, whatever.

Redirect all requests to index.php

Redirect all requests to the index.php. Activate the .htaccess or (better) add the config to the vhost config.

<VirtualHost *:80>
  ServerName redirects.example.com
  ServerAlias www.redirect-domain-1.com ... www.redirect-domain-N.com

  DocumentRoot "/var/www/links/public_html"
  ServerSignature Off
 
  ErrorLog  "/var/log/apache2/links_error.log"
  CustomLog "/var/log/apache2/links_access.log" combined 
   
  # --- Allow access on webroot
  <Directory "/var/www/links/public_html">
    Options -Indexes -FollowSymLinks -MultiViews
    AllowOverride None
    Require all granted
  </Directory>

  ## Rewrite rules
  RewriteEngine On

  RewriteRule ^(.*)$ index.php [QSA,L]

</VirtualHost>

In the DNS point all hostnames with redirects only to this server (i.e. with a CNAME).

Web ui

The web ui is a viewer only - no configuration can be changed. It shows all domains, redirects and is helpful to keep an overview.

This web points to the same document root - should be protected. In the example below is an ip restriction with an additional basic auth (snippet only).

<VirtualHost *:443>
  ServerName links.example.com
  DocumentRoot "/var/www/links/public_html"
  ServerSignature Off

  ErrorLog  "/var/log/apache2/links_error.log"
  CustomLog "/var/log/apache2/links_access.log" combined 
   
  # --- Allow access on webroot
  <Directory "/var/www/links/public_html">
    Options -Indexes -FollowSymLinks -MultiViews
    AllowOverride None
    Require all granted

    <RequireAll>
        # ip restriction: networks with access
        <RequireAny>
            Require ip 192.168.100.0/24
            Require ip 192.168.200.0/24
        </RequireAny>

        # and additional basic auth
        Require valid-user
        AuthType Basic
        # ... basic auth config here
    </RequireAll>

  </Directory>

    SSLEngine on
    SSLCertificateFile      "/etc/ssl/certs/links.example.com.fullchain.cer"
    SSLCertificateKeyFile   "/etc/ssl/certs/links.example.com.key.pem"
    SSLCertificateChainFile "/etc/ssl/certs/links.example.com.fullchain.cer"
    SSLCACertificatePath    "/etc/ssl/certs"

</VirtualHost>