Configuring YOURLS to work with Cherokee Web Server

YOURLS is a set of PHP scripts written by Lester Chan (@GamerZ on Twitter) and Ozh Richard (@Ozh on Twitter) that will allow you to run your own URL shortening service.

It is designed to work with Apache and requires .htaccess support to function. However, a member of the Cherokee Web Server mailing list recently inquired as to whether or not it would work with Cherokee. Good news, it seems to work! All it requires is a few rewrite rules.

I won’t go into detail on the YOURLS configuration as it is very well documented here.

After the initial configuration, here is how you make it work in Cherokee:

1. Select or configure the Virtual Server you intend to use YOURLS on.

2. Add your PHP handler to the Virtual Server if you have not already done so.

2. Add a “File Exists” Behavior with a Handler of “List and Send”

3. Select the option to “Match Any File” and de-select “Only match files” because we want to match directories too in the event you have other content in subdirectories.

4. Add a new behavior with a Type of “Regular Expression”  The RegEx we’re going to match is: ^/([0-9a-z]+)(\+)?(all)?/?$  This regex will match all the contexts in which YOURLS should be called and should provide some additional safety to YOURLS since only requests that “make sense” to YOURLS will be redirected to the YOURLS handler. I don’t know that this is absolutely necessary since the YOURLS code seems quite secure, but it doesn’t hurt!

5. Select the Handler Tab for the “Regular Expression” behavior you just created and add the following RegEx/Substitution records:

Regular Expression: ^/([0-9a-z]+)/?$ Substitution: /yourls-go.php?id=$1

Regular Expression: ^/([0-9a-z]+)\+/?$ Substitution: /yourls-infos.php?id=$1

Regular Expression: ^/([0-9a-z]+)\+all/?$ Substitution: /yourls-infos.php?id=$1&all=1

6. Leave the default “List and Send” handler at the bottom.

7. Save and restart Cherokee.

Here are some screenshots of this configuration in Cherokee in case I missed anything in my notes above.

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Blogplay
  • Reddit
  • StumbleUpon
  • Tumblr
  • Twitter

Related Posts:

This entry was posted in Programming, Server Administration and tagged Cherokee, Linux. Bookmark the permalink.

8 Responses to Configuring YOURLS to work with Cherokee Web Server

  1. Thank you Jeff,

    I am the guy who ask the question in the Cherokee mailing list. Glad that my questions was used to make this post. It works perfect. Check out this link:

    http://bonifaz.ec/yourlscherokee

    Regards,

    Rafael

  2. Pingback: Configuring YOURLS to work with Cherokee Web Server | Online REL

  3. Hi Jeff,

    Anyidea on how to change the default page or even an error handler. Everytime I put http://bonifaz.ec I get an error and if I write a no existent url the same issue. It would be nice, for example, to share stats of my links here or at least redirect to other page.

    Thanks a lot, hopefully you would have an answer.

    Regards from ecuador,

    Rafael

    • Jeff says:

      Should be easy enough to get that to work. I’ll take a look and follow up with you soon! Did you place an index.php file in the yourls directory?

    • Jeff says:

      Updated the post and changed around the approach a little bit. This method seems to work much better.

  4. Jeff says:

    You could also do a “File Exists” behavior, change the condition to “NOT” on the Rule Screen and set the handler to Redirect. Many possibly solutions to getting YOURLS to work. Almost too many. :)

  5. Hi Jeff,

    Sorry for the delay in my answer, but it works great :) . I wonder if things change a lot with yourls 1.5.

    Regards,

    Rafael

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>