Often times I need to place a way to handle short links on sites that manage. Many of the ones out there have many features I do not need and or require significant effort to implement. I needed something quick and simple and could not find one that I liked. I decided to write one.

Features

  • shortlinks are stored in MyQL database
  • Admin Panel interface
  • create a log file of all requests handled ( 404 errors)

This PHP-based script handles shortlinks for websites based on data placed on a mySQL database. It also has a way to manage (add, change, delete) entries via a simple admin page.

It was important to me that the program fit within an existing site with minimal impact ( thus the need to only modify .htaccess and include 4 files. The app handles 404 requests and records to a log file so I can check what is being requested

Sample demo site: https://404handlerdemo.jorgep.com/

Requirements

  • Access to a MySQL database server ( Script will create the table if not already there, but needs the DB credentials )
  • php v5.7 or better.

Core Files:

404handler.php // core front-end shortlink handler
404appLanding.html // landing page when a shortlink is not found. ( can be modified in 404appConfigPROD.php file)
404appConfigPROD.php // configuration file (database creds and other variables)
404appFunctions.php // common PHP functions files
404appAdmin.php // admin interface to add/edit/delete db records

Additional supporting (not needed for operatios) …. )
read.md // Readme file
404appConfig-SAMPLE.php // SAMPLE configuration file
404appSample-htaccess.txt // SAMPLE .htaccess file

Installation

  • download and unzip the latest 404appHandler.zip to a local directory
  • copy or rename 404appConfigSAMPLE.php to 404appConfigPROD.php
  • Modify setting 404appConfigPROD.php to correct database credentials ( there are other parameters there as well but defaults will work well.)
  • move the core files to your webserver root directory (via upload pannel or FTP )
  • Modify .htaccess on root directory file to include the follwing 2 lines:
RewriteEngine On
ErrorDocument 404 /404handler.php