Beantin webbkommunikation

Beantin Beta Blog

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

Generating automatic QR codes with YOURLS

When launched a few weeks ago, they included a feature where adding .qr to the end of a link produced a QR Code for the link. 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 a with Google’s shortener, and as a QR code. Similarly with and as a 2d barcode.


I run my own hosted URL shortener using YOURLS on my 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. is my shortener link to this page, and produces a QR code


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/?$
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...


Filed under Configuration.

Tags: , , ,

  • Getting a redirect to the same page with a 500 error. Yourls 1.5 on a shared host account.

  • I’m getting sent to the root.I tried and I get redirected to http://wrdpg.usAny ideas?
    I am using YOURLS 1.5

    • Hi there Glen and Enkerli,

      I’m running YOURLS 1.4 and Apache on my own webserver. I haven’t had time yet to upgrade to 1.5 and make sure the above solution still works.

      It should though, as I’m not doing anything to YOURLS, it’s working at the web server/apache level – what is important though is that the redirect rule is before the YOURLS rules (and that it doesn’t “clash” with any other rule you’ve got)

  • Maybe the rules from 1.5 clash with these QR code rules? I’m no Apache expert, so I’m not clear on what the clashes look like.

    From scratch, my .htaccess looks like this, after Yourls installation:


    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /yourls-loader.php [L]


    The QR code rule goes where?
    Sorry for the newbie question but I’m sure it can help others.

    • Put the QR code ReWriteRule immediately before the yourls-loader.php ReWriteRule.

      • That’s what I did. I now get a 500 on a shortened URL and a 302 on the .qr version.
        Here’s my modified .htaccess:

        # BEGIN YOURLS

        RewriteEngine On
        RewriteBase /
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^([0-9A-Za-z]+).qr/?$×200&chl=http://%{HTTP_HOST}/$1
        RewriteRule ^(.*)$ /yourls-loader.php [L]

        # END YOURLS

        Can .htaccess conflict with one another? Doesn’t the local one take precedence?

  • Joe

    You’re missing the LAST directive from your rewite. Without it, Apache will continue until it hits the default YOURLs statement and execute that instead – which will redirect you to the root. Here is the fixed version:
    RewriteRule ^([0-9A-Za-z]+).qr/?$
    cht=qr&chs=200×200&chl=http://%{HTTP_HOST}/$1 [L]

  • Toddlrice

    Hello, i am a noob but curious as to how this would work>>>  I am wanting to host my qrcodes, I created some for offline campaign but the provider is now down and lost my tracking and qr directs..
    How can i take the codes I have and implement them into this so i can control the qr codes on my doimain??/

    • Hi Todd, if you encoded someone else’s short url in the code; then there’s nothing much you can do for codes you have already produced. This is the advantage of using your own domain/short URLs in QR Codes – you control them and can point them where ever you want.

Theme Beantin created by James Royal-Lawson. Privacy Policy