Sticky Notes is a light weight pastebin application written in PHP. I installed it at paste.ohai.su, but unfortunately the clean urls didn’t work with lighttpd. While Lighttpd has a mod_rewrite module, it does not use the .htaccess file, which specifies the rewrite rules. So I had to do a few adjustments to get it to work.
-
Enable the mod_rewrite module in lighttpd.
Open your lighttpd config file, that can be found at /etc/lighttpd/lighttpd.conf. The server.modules array should contain a mod_rewrite line. If it does, remove the comment. If it doesn’t exist, simply add it. (Make sure that every entry, except the last one, has a comma behind it). The next time you restart your Lighttpd it is going to load the module.
-
Add the Sticky Notes rewrite rules
Lighty needs to know how to rewrite the urls. Apache uses the .htaccess file for this, but Lighttpd gets the rules from it’s config. So you have to take the rules from the .htaccess file and put them into your lighttpd.conf. As it’s kind of annoying to change the syntax to the one used in lighttpd configs, I’ll provide my config.
$HTTP["host"] =~ "paste\.ohai\.su" { url.rewrite-once = ("^/doc/([a-z]+)/?$" => "doc.php?cat=$1", "^/~([a-z.]+)/doc/([a-z]+)/?$" => "doc.php?project=$1&cat=$2", # Home page links "^/~([a-z.]+)/?$" => "index.php?project=$1", "^/~([a-z.]+)/api/([a-z]+)/?$" => "index.php?project=$1&mode=$2", # Paste list "^/all/?$" => "list.php", "^/api/([a-z]+)/all/?$" => "list.php?mode=$1", "^/~([a-z.]+)/all/?$" => "list.php?project=$1", "^/~([a-z.]+)/api/([a-z]+)/all/?$" => "list.php?project=$1&mode=$2", "^/rss/?$" => "list.php?rss=1", "^/~([a-z.]+)/rss/?$" => "list.php?project=$1&rss=1", "^/all/([0-9]+)/?$" => "list.php?page=$1", "^/api/([a-z]+)/all/([0-9]+)/?$" => "list.php?mode=$1&page=$2", "^/~([a-z.]+)/all/([0-9]+)/?$" => "list.php?project=$1&page=$2", "^/~([a-z.]+)/api/([a-z]+)/all/([0-9]+)/?$" => "list.php?project=$1&mode=$2&page=$3", # General links "^/([0-9]+)/?$" => "show.php?id=$1", "^/~([a-z.]+)/([0-9]+)/?$" => "show.php?project=$1&id=$2", "^/([0-9]+)/([a-z|A-Z]+)/?$" => "show.php?id=$1&mode=$2", "^/~([a-z.]+)/([0-9]+)/([a-z|A-Z]+)/?$" => "show.php?project=$1&id=$2&mode=$3", "^/api/([a-z|A-Z]+)/([0-9]+)/?$" => "show.php?mode=$1&id=$2", "^/~([a-z.]+)/api/([a-z|A-Z]+)/([0-9]+)/?$" => "show.php?project=$1&mode=$2&id=$3", "^/([0-9]+)/([0-9]+)/?$" => "show.php?id=$1&hash=$2", "^/~([a-z.]+)/([0-9]+)/([0-9]+)/?$" => "show.php?project=$1&id=$2&hash=$3", "^/([0-9]+)/([0-9]+)/([a-z|A-Z]+)/?$" => "show.php?id=$1&hash=$2&mode=$3", "^/~([a-z.]+)/([0-9]+)/([0-9]+)/([a-z|A-Z]+)/?$" => "show.php?project=$1&id=$2&hash=$3&mode=$4", "^/api/([a-z|A-Z]+)/([0-9]+)/([0-9]+)/?$" => "show.php?mode=$1&id=$2&hash=$3", "^/~([a-z.]+)/api/([a-z|A-Z]+)/([0-9]+)/([0-9]+)/?$" => "show.php?project=$1&mode=$2&id=$3&hash=$4", "^/api/([a-z|A-Z]+)/([0-9]+)/([0-9]+)/(.*)$" => "show.php?mode=$1&id=$2&hash=$3&password=$4", "^/~([a-z.]+)/api/([a-z|A-Z]+)/([0-9]+)/([0-9]+)/(.*)$" => "show.php?project=$1&mode=$2&id=$3&hash=$4&password=$5" ) }
If you don’t have subdomains or something like that, you don’t need the _$HTTP["host"]_ part. Then just paste the part with _url.rewrite-once_. After you’ve done this, restart your lighttpd (probably *sudo /etc/init.d/lighttpd restart*)
-
Edit the Sticky Notes navigation
I’m not entirely sure if this step really is necessary, but I needed to do it. It’s probably the best if you just open your Stick Notes and check if the urls are correct. (/1000/ instead of show.php?id=1000) In case they are correct already, you are finished and don’t need this last step.
If they aren’t correct, you have to open the classes/class_nav.php file located in your Sticky Notes installation. Replace the check_rewrite() function with this.
function check_rewrite() { return true; }
This simply tells Sticky Notes that the rewrite module is active, without actually checking, as the check would return false. When this is false, the urls link to the unclean versions.
Your Sticky Notes should now use clean urls and work like a charm :)