This is a plugin for the YOURLS link shortener that handles typos and other "near-misses" for any shortened link. It is helpful when conveying shortlinks via printed or otherwise non-clickable media.
Manually typing shortened URLs often leads to a "1" being confused for an "l", "0" for "O", etc. This plugin will intercept any non-existent keyword request and find "close" matches in the database using the Levenshtein string similarity algorithm. This plugin can also handle requests for the root URL of your YOURLS installation, using the same display template as above.
- Install YOURLS on your server
- Install/create a
LEVENSHTEIN()
function to your MySQL server (See "MySQL Options", below.) - Download the code from this repository
- Place the code into the
user/plugins/ltc-ltc-fuzzy-keyword-suggestions/
directory - Log into the YOURLS administration page and activate the plugin
- Optionally customize the results page using the included default template
MySQL does not natively provide a LEVENSHTEIN()
function, but you have several options to provide it.
- Install a User-Defined Function (UDF) module. This has a 500-1000x performance benefit over the second option, in my testing - but it does require administrative access to your database server host. The Levenshtein-MySQL-UDF project on GitHub worked perfectly on a MySQL 5 server in my testing.
- Create a database-level function. This only requires
CREATE ROUTINE
privileges to your YOURLS MySQL database, but it is much slower. This repository includes amysql_levenshtein_function.sql
file that may help, and this Stack Overflow thread may also be of assistance. Note that the plugin will NOT activate if you do not have an available MySQL function namedLEVENSHTEIN()
.
No special usage instructions are required - the plugin should work right "out of the box". However, you may want to take a few steps to optimize and polish the experience.
- Customize the output template. Using the
template-default.php
file as a guideline, create a file namedtemplate.php
in the plugin directory. There are examples intemplate-default.php
showing how to provide meaningful output as well as how to reference external resources such as images, stylesheets, etc. - Ensure the title values in the YOURLS database are meaningful. You can choose to include these Title values in the list of suggested links, which will help your users to confirm they are going to the correct intended resource.
Licensed under the MIT License.