What your Cherokee Web Server config for YOURLS, a self-hosted URL shortener, may look like - heavily based off of a guide by Jeff on UtuTech (Link through Wayback Machine)
Edit the user/config.php
file, as detailed on the YOURLS site.
One suggestion is to add 'admin' to the list of reserved URL keywords, to prevent potential issues with URL rewrite rules. Otherwise, the configuration is standard.
Note: These rules assume your YOURLS site is at the document root. If it is located in a subdirectory, you may need to make a few changes.
- Select or configure the Virtual Server you intend to use YOURLS on.
- Add your PHP handler to the Virtual Server if you have not already done so.
- Open the behavior rules management.
- Add a new behavior with a type of "Regular Expression". The RegEx we're going to match is
^\/admin(*SKIP)(*FAIL)|^\/([0-9a-z]+)(\+)?(all)?\/?$
. (Kudos to @eionrobb for assisting with this.) - Select the Handler tab for the Regular Expression just created, and add the following RegEx/Substitution records:
Type | Regular Expression | Substitution |
---|---|---|
Internal | ^/([0-9a-z]+)/?$ |
/yourls-go.php?id=$1 |
Internal | ^/([0-9a-z]+)\+/?$ |
/yourls-infos.php?id=$1 |
Internal | ^/([0-9a-z]+)\+all/?$ |
/yourls-infos.php?id=$1&all=1 |
- Leave the default "List and Send" handler at the bottom.
- Save and restart Cherokee.
While Cherokee documentation does not recommend directly editing the configuration file, you can also do so by adding the following entries.
Note: You will most likely need to change the rule number to be 100 higher than your existing rules for the vServer. This only includes the rewrite rule.
vserver!6!rule!600!handler = redir
vserver!6!rule!600!handler!rewrite!10!regex = ^/([0-9a-z]+)/?$
vserver!6!rule!600!handler!rewrite!10!show = 0
vserver!6!rule!600!handler!rewrite!10!substring = /yourls-go.php?id=$1
vserver!6!rule!600!handler!rewrite!20!regex = ^/([0-9a-z]+)\+/?$
vserver!6!rule!600!handler!rewrite!20!show = 0
vserver!6!rule!600!handler!rewrite!20!substring = /yourls-infos.php?id=$1
vserver!6!rule!600!handler!rewrite!30!regex = ^/([0-9a-z]+)\+all/?$
vserver!6!rule!600!handler!rewrite!30!show = 0
vserver!6!rule!600!handler!rewrite!30!substring = /yourls-infos.php?id=$1&all=1
vserver!6!rule!600!match = request
vserver!6!rule!600!match!request = ^\/admin(*SKIP)(*FAIL)|^\/([0-9a-z]+)(\+)?(all)?\/?$