<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Factor Mystic &#187; htaccess</title>
	<atom:link href="http://factormystic.net/blog/category/htaccess/feed" rel="self" type="application/rss+xml" />
	<link>http://factormystic.net/blog</link>
	<description></description>
	<lastBuildDate>Mon, 05 Jul 2010 18:27:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How to run Ruby scripts in a browser without mod_ruby</title>
		<link>http://factormystic.net/blog/how-to-run-ruby-scripts-in-a-browser-without-mod_ruby</link>
		<comments>http://factormystic.net/blog/how-to-run-ruby-scripts-in-a-browser-without-mod_ruby#comments</comments>
		<pubDate>Wed, 23 Jul 2008 21:38:58 +0000</pubDate>
		<dc:creator>Factor Mystic</dc:creator>
				<category><![CDATA[htaccess]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[web stuff]]></category>

		<guid isPermaLink="false">http://factormystic.net/blog/?p=32</guid>
		<description><![CDATA[I'm sure this is a horror in dozens of ways, but eruby sucks and my host doesn't have mod_ruby. So I got creative. The .htaccess rewrites requests for any file ending in .rb to this handler.php, which confirms that the requested ruby script exists, then executes it and prints the result. //PHP script to execute [...]]]></description>
			<content:encoded><![CDATA[<p>I'm sure this is a horror in dozens of ways, but eruby sucks and my host doesn't have mod_ruby. So I got creative.</p>
<p>The .htaccess rewrites requests for any file ending in .rb to this handler.php, which confirms that the requested ruby script exists, then executes it and prints the result.</p>
<pre class="brush: php">
//PHP script to execute ruby scripts when the host doesn&#039;t have a cgi handler for .rb
//Use with this .htaccess:

/*
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.rb$ handler.php?rb=$1.rb [NC,QSA]
*/

$file = $_GET[&#039;rb&#039;];

if(in_array($file, scandir(&#039;.&#039;)))
{
foreach($_REQUEST as $key=&gt;$value) if($key != &#039;rb&#039;) $args .= &quot; $key=&quot;.urlencode($value);
echo exec(escapeshellcmd(&#039;./&#039;.$file.$args));
}
else
{
echo &#039;404- Page not found&#039;;
}
?&gt;
</pre>
<p>Here's an example ruby script using this hack- nothing special to do here at all:</p>
<pre class="brush: ruby">
#!/usr/local/bin/ruby

require &#039;cgi&#039;

print &quot;Hello from Ruby!&lt;br&gt;&quot;
print &quot;All of the input variables:&lt;hr&gt;&quot;

ARGV.each do |arg|
print CGI::unescape(arg.to_s)
print &quot;&lt;br&gt;&quot;
end
</pre>
<p>All the GET, POST, and COOKIE variables are at your fingertips in ARGV! (You could get them with Ruby's CGI module as well.)</p>
<p>So here's what it looks like to users:</p>
<div id="attachment_33" class="wp-caption alignnone" style="width: 510px"><a href="http://factormystic.net/blog/wp-content/uploads/2008/07/ss.jpg"><img class="size-full wp-image-33" title="Screenshot of ruby without mod_ruby hack" src="http://factormystic.net/blog/wp-content/uploads/2008/07/ss.jpg" alt="Screenshot of ruby without mod_ruby hack" width="500" height="194" /></a><p class="wp-caption-text">Screenshot of ruby without mod_ruby hack</p></div>
]]></content:encoded>
			<wfw:commentRss>http://factormystic.net/blog/how-to-run-ruby-scripts-in-a-browser-without-mod_ruby/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (user agent is rejected)
Database Caching 17/26 queries in 0.010 seconds using disk

Served from: factormystic.net @ 2010-09-09 19:15:40 -->