Beantin webbkommunikation

Beantin Beta Blog

Experiments, investigations, and tests of web things
October 12, 2010

Generating automatic QR codes with YOURLS

When Goo.gl launched a few weeks ago, they included a feature where adding .qr to the end of a Goo.gl link produced a QR Code for the link. Bit.ly have started doing the same, using the same .qr extention. The idea being you can quickly generate a code, or transfer a link to your mobile device.

So this page for example is http://goo.gl/fBx a with Google’s shortener, and http://goo.gl/fBxa.qr as a QR code. Similarly http://bit.ly/aKAC4j with Bit.ly and http://bit.ly/aKAC4j.qr as a 2d barcode.

YOURLS

I run my own hosted URL shortener using YOURLS on my t1n.se domain. It doesn’t natively support the generation of QR code, but there was a discussion earlier in the year. The main result of that was an awkward “plug-in” which in my eyes over complicates the issue.

In reality it’s very straight forward. http://t1n.se/gaqrc is my shortener link to this page, and http://t1n.se/gaqrc.qr produces a QR code

How?

Just add the following line to the .htaccess file in your YOURLS installation directory. Add it as the first RewriteRule (ie before any YOURLS ReWriteRules).

RewriteRule ^([0-9A-Za-z]+).qr/?$ http://chart.apis.google.com/chart?
cht=qr&chs=200x200&chl=http://%{HTTP_HOST}/$1 [L]

Then that’s it. Job done!

It’s worth noting that this tip isn’t limited to YOURLS, it will work for any Apache based webserver (but check that the RewriteRule doesn’t clash with anything else you have setup).

Related Posts Plugin for WordPress, Blogger...

Tags

Filed under Configuration.

Tags: , , ,

Theme Beantin created by James Royal-Lawson. Privacy Policy