<?xml version="1.0" encoding="utf-8"?>
        <?xml-stylesheet type="text/css" href="http://www.linuxevolution.org/styles/feed.css"?>
<rss version="2.0"
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns:dc="http://purl.org/dc/elements/1.1/"
 xmlns:admin="http://webns.net/mvcb/"
 xmlns:atom="http://www.w3.org/2005/Atom"
>
<channel>
<title>Filed under: lighttp | Linux Evolution dot org and the NSLU2</title>
<atom:link href="http://linuxevolution.org/archives/lighttp/index-rss.xml" rel="self" type="application/rss+xml" />
<link>http://linuxevolution.org</link>
<description></description>
<dc:language>en-us</dc:language>
<dc:creator>orvtech</dc:creator>
<dc:date>2010-12-26T18:58:30-05:00</dc:date>
<admin:generatorAgent rdf:resource="http://nanoblogger.sourceforge.net" />

<item>
<link>http://linuxevolution.org/archives/2010/03/26/a_bash_cgi_as_a_workaround_to__htaccess_files_on_lighttpd/index.html</link>
<guid isPermaLink="true">http://linuxevolution.org/archives/2010/03/26/a_bash_cgi_as_a_workaround_to__htaccess_files_on_lighttpd/index.html</guid>
<title>A BASH CGI as a workaround to .htaccess files on lighttpd</title>
<dc:date>2010-03-26T12:49:32-05:00</dc:date>
<dc:creator>orvtech</dc:creator>
<dc:subject> Scripts, NSLU2, Linux, nanoblogger, lighttp</dc:subject>
<description><![CDATA[<p>
As you might remember, in a previous post I explained how to maintain a permanent link which always points 
to the latest submission on your nanoblogger website. Since I decided to migrate from apache to lighttp I 
lost the ability to use .htacees files thus .htacees file based redirects do not work anymore.
</p>
<p>
<br /><b>The workaround.</b><br />

We will keep using the /latest url for the redirects the only thing is that we will use a CGI written in 
BASH to accomplish the redirect. The script will parse our RSS feed (rss.xml) to check which is the latest 
post and redirect to that url. The redirect is accomplished by sending the HTTP headers 'Location' and 
'Status'. Let's take a look at the script:
<br />
<i>latest.cgi</i><br />

<textarea style="height: 80px" class="bashcode">
#!/bin/bash
DocummentRoot="/var/www/linuxevolution.org/htdocs"
Latest=`cat $DocummentRoot/rss.xml | grep link | grep archives | head -n1 | sed -e :a -e 's/<[^>]*>//g;/</N;//ba'`
echo "Status: 302 Moved"
echo -e "Location: $Latest\n"</textarea>
</p>
<p>
Here we are sending the Status header to prevent search engines from associating more than one url to the 
same content (this will give us a lower score in some search engines' systems) and then we send the 
Location header to do the actual redirect.
</p>
<p>
<br /><b>Lighttp and CGIs.</b><br />

In other to execute this CGI we need to make some minor modifications to our VirtualHostost configuration. 
Lets add these two lines to it:
<br />

<textarea style="height: 26px" class="bashcode">
cgi.assign = ( ".cgi" => "/bin/bash" )
url.redirect =( "^/latest/(.*)" => "http://www.linuxevolution.org/latest.cgi")</textarea>


</p>
<p>
In the first line we are telling lighttpd to use /bin/bash to execute any *.cgi file (you can change this 
to anything like *.sh, *.bash). In the second line we redirect all requests to /latest/ to the url 
/latest.cgi. You can either use /latest.cgi or /latest/ for these urls in your signature at the forums; 
personally I like to use /latest/<name of the forum here> to keep track of where is my traffic coming from 
even if I don't get the HTTP referrer.
</p>
<br />
<p><i>
<b>Spanish version:</b> <a href="http://orvtech.com/howto/un-cgi-en-bash-para-mantener-tu-firma-al-dia-en-todos-los-foros-en-que-participas/" rel="friend" hreflang="es">Un CGI en BASH para mantener tu firma al dia en todos los foros en que participas.</a>
</i></p>]]></description>

</item>
</channel>
</rss>

