Jun 162011

nginxOn my site I had a small problems with feeds, i’ve them managed with feedburner and I’ve 1 feed for every language, so you can choose to have the feeds in English or in Italian. The problem is that I’d like that when a user write http://linuxaria.com/feed it land on my feedburner page for English while writing http://linuxaria.com/feed?lang=it he should lands on the Italian feed page.

I’ve tried with the wordpress plugin for feedburner, but that it’s good only if you have 1 feed, because it blindly redirect everything to 1 feedburner address, so it’s not a good solution for my 2 bilingual feeds.

And so I’ve done it with a rewrite in Nginx.

In Nginx (version 1.0.2) is not possible to concatenate conditions so I’ve made 2 different conditions

1) Check if the query string contains lang=it

if ($args ~ lang=it) {
        set $test  IT; 

2) Check if the user agent is NOT Feedburner

if ($http_user_agent !~ FeedBurner) {
        set $test  "${test}F";

This condition take the value of ${test} and add F to it if the User agent isn’t Feedburner.

3) Put the 2 conditions together to send Italian Users to the correct feed:

if ($test = ITF) {
    rewrite ^/feed/?$ http://feeds.feedburner.com/Linuxaria_It last;

using the directive last with tell Nginx to stop processing rules.

4) And at last if the User Agent is not Feedburner and language isn’t Italian we send the user to the correct English feed:

if ($test = F) {
    rewrite ^/comment/feed/?$ http://feeds.feedburner.com/CommentsForLinuxaria_En last;
    rewrite ^/feed/?$ http://feeds.feedburner.com/Linuxaria_En last;

This condition first check if the feed is the one for comments, otherwise it send the users to the English feed for posts.


I’m a newbie with Nginx, I’ve more than 10years experience with Apache, but i started to use Nginx only with my VPS, so this could be not the more elegant solution available, and if you have a better one please leave me a comment.
For the moment i can say that it works fine, I’ve my 2 feeds served by feedburner and I’ve removed the WordPress plugin.

Popular Posts:

Flattr this!

 Leave a Reply

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=""> <s> <strike> <strong>