FoOlz.us and how to make YOURLS work with Nginx.

Sometimes I wonder… why do I do such things?
Well, honestly I am a megalomaniac, and all the most famous websites have an URL shortening service for their own service. Since (one day) FoOlRulez will be the biggest website evar, I thought… why not adding the short URL service early? Doing it was far harder than thinking of it.
You know, we aren’t using a LAMP (Linux-Apache-MySQL-PHP) server, but an Nginx powered server (LNMP sounds weird tho). This means most of the software needs some fix to work correctly, though it will work much faster. This means YOURLS, the software I intended to use, needed some fix as well.
For this fix, I had to find a solution, and I have found it here: 使用 Yourls 强化你的短网址系统 – Showfom’s Blog.
I have no idea what that URL says… but hey, I found the fix to make YOURLS work!
if (!-f $request_filename){
set $rule_0 1$rule_0;
}
if (!-d $request_filename){
set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
rewrite ^/([0-9a-z]+)/?$ /yourls-go.php?id=$1 last;
}
Gibberish? No this is the code you need to make it work in your Nginx installation! Paste it where you need it. If you don’t know how comment here and I’ll explain a bit further.
Anyway, this made everything work… a bit of styling of the homepage et voilà!
It works! I can’t believe it myself!
Let’s go a bit more indeep with YOURLS. This is a very complete script to make your own URL shortener, by:
- Lester Chan / @GamerZ on Twitter
- Ozh RICHARD / @Ozh on Twitter
I think they’re the same who made a few of the plugins I use in this WordPress blog (yeah they are). Anyway, this script is powerful enough to not leave you dry mouthed: you get an API to use the URL shortening service on your server from anywhere, the admin menu lets you control the tidbits you need (ok, most of the controls are via code, but it’s easily done with the explanations), the code has explanation for most of the lines – I in fact edited it to fit my needs better.
Best part of all, it comes with a WordPress plugin, that hooks to the shortening service and makes a short url for every post: even this one post has a shortening url. Then you get automatic submission of the post to Twitter after publishing. The button to submit to twitter on the top is my creation by using the functions (wordpress hooks) that YOURL for WordPress provides.
@gamerz @ozh Thanks for YOURLS =) “FoOlz.us and how to make YOURLS work with Nginx.” http://foolrulez.org/blog/2009/08/foolz-...
@woxxy Awesome! I’m adding this to the readme. Stay tuned, next version has link stats & more :)
@woxxy no problem =D
I love it woxxy.
Keep up the good work.
PS:
http://foolz.us/a = /a/
http://foolz.us/b = /b/
:3
The URL you linked above says “Use your short-Yourls enhanced web-based system – Showfom’s Blog.” /google translated =P
So this is basically like Tinyurl/bit.ly huh?
Lol, thanks for the auto-translation Nyarth.
And yeah, that’s exactly what it does.
Oh hey, this is pretty cool.
Once the database “registers” a custom keyword, does it expire after a while?
Or is it permanently stored?
It’s permanent. More precisely, as long as FoOlRulez exists.
Whoa that’s the awesome.
What? DickensUrl wasn’t good enough for you?
FoOls: http://dickensurl.com/bf68/*an immensely long url*
Oh, shoot, I broke the blog. Sorry D:
lol you keep breaking stuff.
This is pretty cool.
Haha so you use Nginx, too. I love it~
Ok, I don’t know where to put the code above. Please help. Thanks!
Yeah, I am about to learn how to manage my own database. Good work!
woxxy
Thanks for providing the Nginx rewrite. It works!!!
Help!
It didn’t work for me.
The relevant configuration:
server {
listen 74.207.227.150:80; ## listen for ipv4
listen [2001:470:8:1ae::2]:80; ## listen for ipv6
server_name n4rky.me http://www.n4rky.me;
root /home/www/n4rky.me;
access_log /home/www/n4rky.me/logs/access.log;
location / {
index index.php;
if (!-f $request_filename){
set $rule_0 1$rule_0;
}
if (!-d $request_filename){
set $rule_0 2$rule_0;
}
if ($rule_0 = “21″){
rewrite ^/([0-9a-z]+)/?$ /yourls-go.php?id=$1 last;
}
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SERVER_NAME $http_host;
fastcgi_ignore_client_abort on;
}
location ~ /\.ht {
deny all;
}
}
My guess is that it isn’t the rewrite rules you found but the fastcgi implementation. Any ideas?
Thanks!
Based on the contents of the .htaccess file generated by Yourls, this seems to be the most direct translation to Nginx config (seems to be working fine for me, though I didn’t bother to translate the ‘path’ prefix, as I don’t need it):
if (!-e $request_filename) {
rewrite ^ /yourls-loader.php last;
}
Stay with this guys, you\’re helping a lot of ppeole.
AKAIK you\’ve got the asnewr in one!
3Lxotq urfbnfchkohk
Ks24z9 fgbacgvyslbd
Thanks a million! It works!
That\’s way the bestest anwesr so far!
QpNhWz upgrulgzcgsi
Información Bitacoras.com…Valora en Bitacoras.com: Hace un par de días aiomtssis a la presentación de DJ Hero en las oficinas de Activision en Madrid y aprovechando que hoy sale a la venta el juego en el mercado Español les cuento algunas cosas que vi y mis impresiones sobre …..
Now I\’m like, well duh! Truly tahnkufl for your help.
YROqyc ycqrgwoojcnb
JbTxcv palgpfpiekia