<?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>Simone Carletti&#039;s Blog &#187; apache</title>
	<atom:link href="http://www.simonecarletti.com/blog/tags/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.simonecarletti.com/blog</link>
	<description>Simone Carletti&#039;s personal ramblings on programming, syndication, search engines &#38; marketing.</description>
	<lastBuildDate>Thu, 12 Jan 2012 09:16:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Redmine 0.9.0 and duplicate content issue</title>
		<link>http://www.simonecarletti.com/blog/2009/12/redmine-0-9-0-and-duplicate-content-issue/</link>
		<comments>http://www.simonecarletti.com/blog/2009/12/redmine-0-9-0-and-duplicate-content-issue/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 22:11:31 +0000</pubDate>
		<dc:creator>Simone Carletti</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Server / Apache]]></category>
		<category><![CDATA[Softwares]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[redirects]]></category>
		<category><![CDATA[redmine]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.simonecarletti.com/blog/?p=886</guid>
		<description><![CDATA[Redmine 0.9.0 duplicates the most part of application URLs: here's an Apache configuration file to redirect the old URLs to the new ones.]]></description>
			<content:encoded><![CDATA[<p>A couple of hours ago I upgraded the <a href="http://code.simonecarletti.com/">code domain</a> from Redmine 0.8.0 to Redmine 0.9.0, currently available in pre-beta.</p>
<p>Redmine 0.9.0 offers tons of improvements but one among all forced my decision to upgrade without waiting for a final release: <strong>Rails 2.3.5</strong>. Redmine 0.8.x is built on Rails 2.1.0 and there seems to be some kind of weird Rails-Redmine-Passenger-Ruby EE memory leaks.</p>
<p>With the new release, Redmine <a title="Redmine - Patch #1901: RESTful URLs for everything - Redmine" href="http://www.redmine.org/issues/1901">has changed</a> the most part of its URLs. The development team basically migrated all routes to a more RESTful-oriented architecture. They did a wonderful job, unfortunately they probably chose the worst way to ensure backward-compatibility: <strong>duplication</strong>.</p>
<p>All the old routes are still available along with the new ones and this can cause several duplicate content issues. To patch the problem, I configured some Apache redirection rules in order to permanently redirect the old URLs to the new ones.<span id="more-886"></span></p>
<p><script src="http://gist.github.com/265300.js?file=redmine-080-to-090.conf"></script></p>
<p>The gist doesn&#8217;t pretend to solve all issues. It&#8217;s just a quick and (quite) dirty fix.</p>
<p>From Redmine side, I would have setup a <a title="Riding Rails: Introducing Rails Metal" href="http://weblog.rubyonrails.org/2008/12/17/introducing-rails-metal">Rails Metal</a> to redirect all the old URLs to the new ones. This is not as efficient as relying on the web server, but this is compatible with any user environment.</p>
<p>Feel free to fork, clone and update the gist. After all, <strong>this is a Git repository</strong>!</p>
<p>Related posts<ol>
<li><a href='http://www.simonecarletti.com/blog/2009/07/configuring-git-repository-with-redmine/' rel='bookmark' title='Configuring a Git repository with Redmine'>Configuring a Git repository with Redmine</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects/' rel='bookmark' title='Apache .htaccess query string redirects'>Apache .htaccess query string redirects</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/12/generic-apache-configuration-snippets/' rel='bookmark' title='Generic Apache configuration snippets'>Generic Apache configuration snippets</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.simonecarletti.com/blog/2009/12/redmine-0-9-0-and-duplicate-content-issue/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Generic Apache configuration snippets</title>
		<link>http://www.simonecarletti.com/blog/2009/12/generic-apache-configuration-snippets/</link>
		<comments>http://www.simonecarletti.com/blog/2009/12/generic-apache-configuration-snippets/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 20:59:14 +0000</pubDate>
		<dc:creator>Simone Carletti</dc:creator>
				<category><![CDATA[Server / Apache]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[gzip]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.simonecarletti.com/blog/?p=780</guid>
		<description><![CDATA[Some generic Apache configuration snippets for various purposes, from Rails to security.]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;m changing server for this blog for the (maybe) fifth time. I&#8217;m doing some server reorganization and I decided to move this site to a small dedicated VPS at <a href="http://manage.aff.biz/z/146/CD2784/">VPS.net</a>. So, if you are reading this message, welcome to the new server!</p>
<p>The most annoying activity, each time I have to configure a clean Linux installation, is to deal with all the small tweak and improvements I applied since the server was originally created. I have more than one server and I like to reuse successful scripts in order to save time and leverage productivity. I often end up improving one script at time and I need the changes to propagate to all the other existing servers.</p>
<p>For this reason, I started to keep track of all those configurations in several different Git repositories. Each time a script is updated, the changes are pushed to the main repository. All the servers are configured to periodically pull changes from the master repository to keep local versions up-to-date.</p>
<p>Because cloning private repositories is almost annoying as copying content by hand, I decided to convert some of my Git repositories into a <a href="http://gist.github.com/">Gist</a>. Here&#8217;s my <a href="http://gist.github.com/252753">Generic Apache configuration snippet repository</a>. It contains some generic configuration snippets for various topics, from Rails to security.<span id="more-780"></span></p>
<h2>How to use the snippet repository</h2>
<p>All the Apache configurations in the repository are self-contained. It means, each configuration is created to be independent from the hostname or other configurations, to make it more flexible and reusable.</p>
<p>To apply a configuration, just <code>Include</code> the file in your Apache or Vhost configuration.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"># /etc/apache2/apache.conf<br />
# Enable compression for all configured vhosts<br />
Include /path/to/compression-gzip.conf</div></td></tr></tbody></table></div>
<p>You can even enable the configuration in a single vhost.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"># /etc/apache2/sites-available/simonecarletti_production.conf<br />
# Enable Rails cache for this vhost<br />
&lt;VirtualHost *:80&gt;<br />
&nbsp; Include /path/to/compression-gzip.conf<br />
&lt;/VirtualHost&gt;</div></td></tr></tbody></table></div>
<p>Depending on your needs, you might want to clone the Git repository on your local machine and selectively include the configuration snippets or just grab the configuration you need for your single virtual host.</p>
<h2>Snippets</h2>
<h3>Apache Gzip Compression</h3>
<p>The following snippet enables the Gzip compression for everything except compressed images. Gzipping your content usually reduces the response size by about 70%. Do you want to learn more? Watch how <a href="http://code.google.com/speed/articles/gzip.html">Gzip compression works</a> and <a href="http://developer.yahoo.com/performance/rules.html">why it&#8217;s so important</a>.</p>
<p><script src="http://gist.github.com/252753.js?file=compression-gzip.conf"></script></p>
<h3>Rails Cache</h3>
<p>The following two snippets are meant to be used in combination with <a href="http://guides.rubyonrails.org/caching_with_rails.html#page-caching">Rails page caching</a>. They instruct Apache to look for a cached resource in the <code>/cache</code> folder and serve the content from the directory if the file exists.  <script src="http://gist.github.com/252753.js?file=rails-cache.conf"></script><br />
<script src="http://gist.github.com/252753.js?file=rails-cache-by-host.conf"></script></p>
<h3>Redirect Not-WWW to WWW</h3>
<p>This is a really generic Not-WWW to WWW configuration script. Unlike most existing scripts, it doesn&#8217;t force you to manually inject the server name. Just include the snippets and you&#8217;re ready. If you are looking for a less exotic configuration, have a look at the <a href="http://www.searchmarketingarena.com/questions/243/how-to-301-redirect-non-www-to-www-version">How to 301 redirect Not-WWW to WWW version</a> question at Search Marketing Arena.  <script src="http://gist.github.com/252753.js?file=redirect-not-www-to-www.conf"></script></p>
<h3>Security Rules</h3>
<p>In the attempt to reduce the amount of spam comments sent to my blogs, I extracted some recurrent patterns from my server logs and created some super-simple rules to kick out automated script. Basically, this is the same idea behind <a href="http://www.modsecurity.org/">mod_security</a>, with the (huge) difference my set of rules it much more simple but much more lightweight.</p>
<p><script src="http://gist.github.com/252753.js?file=security-rules.conf"></script></p>
<p>All configuration snippets are available free of charge and without any warranty. Use them at your own risk.</p>
<p>Related posts<ol>
<li><a href='http://www.simonecarletti.com/blog/2009/01/logging-external-referers-with-apache/' rel='bookmark' title='Logging external referers with Apache'>Logging external referers with Apache</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects/' rel='bookmark' title='Apache .htaccess query string redirects'>Apache .htaccess query string redirects</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/02/apache-log-regex-a-lightweight-ruby-apache-log-parser/' rel='bookmark' title='Apache Log Regex: a lightweight Ruby Apache log parser'>Apache Log Regex: a lightweight Ruby Apache log parser</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.simonecarletti.com/blog/2009/12/generic-apache-configuration-snippets/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Apache Log Regex: a lightweight Ruby Apache log parser</title>
		<link>http://www.simonecarletti.com/blog/2009/02/apache-log-regex-a-lightweight-ruby-apache-log-parser/</link>
		<comments>http://www.simonecarletti.com/blog/2009/02/apache-log-regex-a-lightweight-ruby-apache-log-parser/#comments</comments>
		<pubDate>Sat, 14 Feb 2009 09:03:02 +0000</pubDate>
		<dc:creator>Simone Carletti</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[apachelogregex]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[parser]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.simonecarletti.com/blog/?p=168</guid>
		<description><![CDATA[ApacheLogRegex is designed to be a simple Ruby class to parse Apache log files.]]></description>
			<content:encoded><![CDATA[<p>This is going to be a really fruitful month for me. I completed a couple of long-time standing activities and I finally had some time to go back working on <a href="http://code.simonecarletti.com/">my Ruby GEMS</a>. After the third version of my <a title="WWW::Delicious 0.3.0 -  Search &amp; Refactor" href="http://www.simonecarletti.com/blog/2009/02/www-delicious-030/">Ruby client for delicious API</a>, this is the turn of <a title="Apache Log Regex - Overview - Simone Carletti's Codestuffs" href="http://code.simonecarletti.com/apachelogregex">Apache Log Regex</a>.</p>
<p><strong>ApacheLogRegex is designed to be a simple Ruby class to parse Apache log files</strong>. It takes an Apache logging format and generates a regular expression which is used to parse a line from a log file and returns a Hash with keys corresponding to the fields defined in the log format.</p>
<p><span id="more-168"></span>Take for example the following Apache log entry.</p>
<div class="codecolorer-container text default brush: plain" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">87.18.183.252 - - [13/Aug/2008:00:50:49 -0700] &quot;GET /blog/index.xml HTTP/1.1&quot; 302 527 &quot;-&quot; &quot;Feedreader 3.13 (Powered by Newsbrain)&quot;</div></td></tr></tbody></table></div>
<p>You can easily parse it with Apache Log Regex and extract only the information you need.</p>
<div class="codecolorer-container text default brush: ruby;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"># This is the log line you want to parse<br />
line = '87.18.183.252 - - [13/Aug/2008:00:50:49 -0700] &quot;GET /blog/index.xml HTTP/1.1&quot; 302 527 &quot;-&quot; &quot;Feedreader 3.13 (Powered by Newsbrain)&quot;'<br />
<br />
# Define the log file format.<br />
# This information is defined in you Apache log file<br />
# with the LogFormat directive<br />
format = '%h %l %u %t \&quot;%r\&quot; %&gt;s %b \&quot;%{Referer}i\&quot; \&quot;%{User-Agent}i\&quot;'<br />
<br />
# Initialize the parser<br />
parser = ApacheLogRegex.new(format)<br />
<br />
# Get the log line as a Hash<br />
parser.parse(line)<br />
# =&gt; {&quot;%r&quot;=&gt;&quot;GET /blog/index.xml HTTP/1.1&quot;, &quot;%h&quot;=&gt;&quot;87.18.183.252&quot;, &quot;%&gt;s&quot;=&gt;&quot;302&quot;, &quot;%t&quot;=&gt;&quot;[13/Aug/2008:00:50:49 -0700]&quot;, &quot;%{User-Agent}i&quot;=&gt;&quot;Feedreader 3.13 (Powered by Newsbrain)&quot;, &quot;%u&quot;=&gt;&quot;-&quot;, &quot;%{Referer}i&quot;=&gt;&quot;-&quot;, &quot;%b&quot;=&gt;&quot;527&quot;, &quot;%l&quot;=&gt;&quot;-&quot;}</div></td></tr></tbody></table></div>
<p>If you want more control over the parser you can use the <code>parse!</code> method. It raises a <code>ParseError</code> exception if given line doesn&#8217;t match the log format.</p>
<div class="codecolorer-container text default brush: ruby;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">common_log_format = '%h %l %u %t &quot;%r&quot; %&gt;s %b'<br />
parser = ApacheLogRegex.new(common_log_format)<br />
<br />
# No exception<br />
parser.parse(line) # =&gt; nil<br />
<br />
# Raises an exception<br />
parser.parse!(line) # =&gt; ParseError</div></td></tr></tbody></table></div>
<p>Instead of spending time parsing one line at once you can read entire log files and feed the parser collecting the final result.</p>
<div class="codecolorer-container text default brush: ruby;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">result = File.readlines('/var/apache/access.log').collect do |line|<br />
&nbsp; parser.parse(line)<br />
end</div></td></tr></tbody></table></div>
<p>Apache Log Regex is a Ruby port of Peter Hickman&#8217;s Apache::LogRegex 1.4 Perl module, available at http://cpan.uwinnipeg.ca/~peterhi/Apache-LogRegex.</p>
<p>You can install the library via RubyGems.</p>
<div class="codecolorer-container text default brush: bash" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ gem install apachelogregex</div></td></tr></tbody></table></div>
<p>Feel free to email me with any questions or feedback. For the documentation and more details you can visit the <a title="Apache Log Regex - Overview - Simone Carletti's Codestuffs" href="http://code.simonecarletti.com/apachelogregex">ApacheLogRegex project page</a>.</p>
<p>Related posts<ol>
<li><a href='http://www.simonecarletti.com/blog/2009/09/ruby-whois-preview-answer-and-parser/' rel='bookmark' title='Ruby Whois preview: WHOIS answer and parser'>Ruby Whois preview: WHOIS answer and parser</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/01/logging-external-referers-with-apache/' rel='bookmark' title='Logging external referers with Apache'>Logging external referers with Apache</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects/' rel='bookmark' title='Apache .htaccess query string redirects'>Apache .htaccess query string redirects</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.simonecarletti.com/blog/2009/02/apache-log-regex-a-lightweight-ruby-apache-log-parser/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Apache RewriteRule and query string</title>
		<link>http://www.simonecarletti.com/blog/2009/01/apache-rewriterule-and-query-string/</link>
		<comments>http://www.simonecarletti.com/blog/2009/01/apache-rewriterule-and-query-string/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 08:05:16 +0000</pubDate>
		<dc:creator>Simone Carletti</dc:creator>
				<category><![CDATA[Server / Apache]]></category>
		<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[querystring]]></category>

		<guid isPermaLink="false">http://www.simonecarletti.com/blog/?p=135</guid>
		<description><![CDATA[A quick reference for dealing with query string in Apache rewrite rules.]]></description>
			<content:encoded><![CDATA[<p>At first look, the way Apache <code>mod_rewrite</code> module deals with query strings can be a little confusing. From <a href="http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritecond">the RewriteRule documentation</a>:</p>
<blockquote><p><strong>qsappend|QSA&#8217; (query string append)</strong><br />
This flag forces the rewrite engine to append a query string part of the substitution string to the existing string, instead of replacing it. Use this when you want to add more data to the query string via a rewrite rule.</p></blockquote>
<p>Let&#8217;s try to <a href="http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects/">redirect a page depending on its query string</a>. Our rewrite rule should looks like this:</p>
<div class="codecolorer-container text default brush: apache;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">RewriteCond %{QUERY_STRING} ^id=([0-9]*)$<br />
RewriteRule ^page\.php$ http://mydomain.site/page/%1.php [R=302,L]</div></td></tr></tbody></table></div>
<p><span id="more-135"></span>According to the official documentation, you would expect the following behavior:</p>
<div class="codecolorer-container text default brush: text;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">/page.php?id=37 -&gt; http://mydomain.site/page/37.php<br />
/page.php?id=40 -&gt; http://mydomain.site/page/40.php<br />
# and so on</div></td></tr></tbody></table></div>
<p>However, if you don&#8217;t append something new, then <strong>the original query is passed through the rules unchanged</strong> by default.</p>
<div class="codecolorer-container text default brush: text;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">/page.php?id=37 -&gt; http://mydomain.site/page/37.php?id=37<br />
/page.php?id=40 -&gt; http://mydomain.site/page/40.php?id=40<br />
# and so on</div></td></tr></tbody></table></div>
<p>If you want to discard the original query string you must append an empty question mark at the end of the rule. Let&#8217;s call it the <strong>query string not append</strong> or <strong>query string discard</strong> flag.</p>
<div class="codecolorer-container text default brush: apache;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">RewriteCond %{QUERY_STRING} ^id=([0-9]*)$<br />
RewriteRule ^page\.php$ http://mydomain.site/page/%1.php&lt;strong&gt;?&lt;/strong&gt; [R=302,L]</div></td></tr></tbody></table></div>
<p>Here&#8217;s a quick reference for dealing with query string in a RewriteRule.</p>
<div class="codecolorer-container text default brush: text;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Keep original query (default behavior)<br />
RewriteRule ^page\.php$ /target.php [L]<br />
# from http://example.com/page.php?foo=bar<br />
# to &nbsp; http://example.com/target.php?foo=bar<br />
<br />
Discard original query<br />
RewriteRule ^page\.php$ /target.php? [L]<br />
# from http://example.com/page.php?foo=bar<br />
# to &nbsp; http://example.com/target.php<br />
<br />
Replace original query<br />
RewriteRule ^page\.php$ /target.php?bar=baz [L]<br />
# from http://example.com/page.php?foo=bar<br />
# to &nbsp; http://example.com/target.php?bar=baz<br />
<br />
Append new query to original query<br />
RewriteRule ^page\.php$ /target.php?bar=baz [QSA,L]<br />
# from http://example.com/page.php?foo=bar<br />
# to &nbsp; http://example.com/target.php?foo=bar&amp;bar=baz</div></td></tr></tbody></table></div>
<p>Related posts<ol>
<li><a href='http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects/' rel='bookmark' title='Apache .htaccess query string redirects'>Apache .htaccess query string redirects</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/01/logging-external-referers-with-apache/' rel='bookmark' title='Logging external referers with Apache'>Logging external referers with Apache</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/12/generic-apache-configuration-snippets/' rel='bookmark' title='Generic Apache configuration snippets'>Generic Apache configuration snippets</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.simonecarletti.com/blog/2009/01/apache-rewriterule-and-query-string/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Logging external referers with Apache</title>
		<link>http://www.simonecarletti.com/blog/2009/01/logging-external-referers-with-apache/</link>
		<comments>http://www.simonecarletti.com/blog/2009/01/logging-external-referers-with-apache/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 15:27:36 +0000</pubDate>
		<dc:creator>Simone Carletti</dc:creator>
				<category><![CDATA[Server / Apache]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[logs]]></category>
		<category><![CDATA[referers]]></category>
		<category><![CDATA[seo]]></category>

		<guid isPermaLink="false">http://www.simonecarletti.com/blog/?p=109</guid>
		<description><![CDATA[How to create a custom Apache log file to track external referrals.]]></description>
			<content:encoded><![CDATA[<p>The default <strong>Apache access log</strong> includes many useful details about each single request to you website. This is an example of how a log entry looks like:</p>
<div class="codecolorer-container text default brush: text;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">79.28.43.25 - - [25/Jan/2009:13:18:02 +0000] &quot;GET /blog/2007/01/internet-explorer-7-in-italiano/ HTTP/1.1&quot; 200 14487 &quot;http://www.google.it/search?hl=it&amp;q=aggiornamento+internet+explorer+&amp;btnG=Cerca+con+Google&amp;meta=&amp;aq=f&amp;oq=&quot; &quot;Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)&quot;</div></td></tr></tbody></table></div>
<p>You can easily identify the client IP address, the request timestamp, the landing page and the referral, in this example represented by a Google Search Page.<br />
<span id="more-109"></span></p>
<h2>Creating a custom referer log file</h2>
<p>As a Marketer or SEO, the referral and the landing page can be really useful information. Extracting them from the default apache log file can be a little tricky and requires some parsing knowledge. For this reason you would find more convenient to <strong>write a custom log file</strong> including only those two details.</p>
<p>Let me show you how. You don&#8217;t need to know much about Apache server management but <strong>you must have access to your virtual host configuration</strong> because the <code>CustomLog</code> and <code>LogFormat</code> directives can&#8217;t be specified in the <code>.htaccess</code> file but only at server config or virtual host level.<br />
Write the following lines either in you Apache configuration file or in your virtual host definition depending on whether you want to create a referer log for all configured websites or just for a single virtual host.</p>
<p>In order to <strong>monitor incoming links</strong> you need to define a custom log format using the <a href="http://httpd.apache.org/docs/2.0/mod/mod_log_config.html#logformat">LogFormat</a> directive and give it an useful name, for example <code>referer</code>.</p>
<div class="codecolorer-container text default brush: apache;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">LogFormat &quot;%{Referer}i %U&quot; referer</div></td></tr></tbody></table></div>
<p>Then ask Apache to generate a new log passing the custom format.</p>
<div class="codecolorer-container text default brush: apache;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CustomLog /path/to/folder/referer.log referer</div></td></tr></tbody></table></div>
<p>You can specify as many <code>CustomLog</code> as you want, already configured logs will not be affected. In this case <strong>Apache will generate two logs for each request</strong>: the first one with the default format and the second one including only the referral string and the landing page.</p>
<p>Here&#8217;s an example of a typical virtual host configuration.</p>
<div class="codecolorer-container text default brush: apache;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;VirtualHost *:80&gt;<br />
&nbsp; ServerName &nbsp; &nbsp;example.com<br />
&nbsp; ServerAlias &nbsp; www.example.com<br />
&nbsp; DocumentRoot &nbsp;/var/www/example.com/public<br />
<br />
&nbsp; # many other directives ...<br />
<br />
&nbsp; LogFormat &quot;%{Referer}i %U&quot; referer<br />
&nbsp; CustomLog /var/www/example.com/logs/referer.log referer<br />
&lt;/VirtualHost&gt;</div></td></tr></tbody></table></div>
<p>For each request to <code>example.com</code> Apache will write an entry in the <code>referer.log</code> file including the landing page and the referer string, like the following one.</p>
<p><img class="aligncenter size-medium wp-image-120" title="Referer Log" src="http://www.simonecarletti.com/blog/wp-content/uploads/2009/01/refererlog-400x262.png" alt="Referer Log" width="400" height="262" /></p>
<div class="flash-message warning">
<p>In Apache 2.x the <code>LogFormat</code> name <code>referer</code> appears to be reserved for the format <code>"%{Referer}i -&gt; %U"</code>. You should use a different name to prevent conflicts.</p>
</div>
<h2>Combining LogFormat and CustomLog in a single line</h2>
<p>If you don&#8217;t need to define a reusable <code>LogFormat</code> and you don&#8217;t care to assign it to a format name, you can <strong>create a custom log in one step</strong>.</p>
<div class="codecolorer-container text default brush: apache;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CustomLog /var/www/example.com/logs/referer.log &quot;%{Referer}i %U&quot;</div></td></tr></tbody></table></div>
<p>The line above is equivalent to the following one.</p>
<div class="codecolorer-container text default brush: apache;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">LogFormat &quot;%{Referer}i %U&quot; myformat<br />
CustomLog /var/www/example.com/logs/referer.log myformat</div></td></tr></tbody></table></div>
<h2>Writing a CSV log file</h2>
<p>You can customize the referer log placing as many <a href="http://httpd.apache.org/docs/2.0/mod/mod_log_config.html#logformat">&#8220;%&#8221; directives</a> as you wish in your log format. For example, the following format writes a <acronym title="comma separated values">CSV</acronym> log file.</p>
<div class="codecolorer-container text default brush: apache;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">LogFormat &quot;\&quot;%{Referer}i\&quot;,\&quot;%U\&quot;&quot; referer</div></td></tr></tbody></table></div>
<p>Here&#8217;s an example.</p>
<div class="codecolorer-container text default brush: text;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&quot;http://www.google.com/search?q=keyword&quot;, &quot;/page.html&quot;<br />
&quot;http://www.google.com/search?q=keyword&quot;, &quot;/new-page.html&quot;</div></td></tr></tbody></table></div>
<p>Log entries can be easily parsed or opened with a CSV-compatible software like OpenOffice or Excel.</p>
<p><img class="aligncenter size-medium wp-image-119" title="Referer Excel" src="http://www.simonecarletti.com/blog/wp-content/uploads/2009/01/referer-excel-400x234.png" alt="Referer Excel" width="400" height="234" /></p>
<h2>Logging external referers</h2>
<p>Logging all referrals is expensive and not so effective for marketing analysis. It would probably be a good idea to restrict the directive to <strong>match only external referers</strong>. <a href="http://httpd.apache.org/docs/2.0/env.html">Enviroment Variables</a> are what we need to do this.</p>
<div class="codecolorer-container text default brush: apache;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SetEnvIfNoCase Referer (www\.)?example\.com INTERNAL_REFERRAL<br />
LogFormat &quot;\&quot;%{Referer}i\&quot;,\&quot;%U\&quot;&quot; referer<br />
CustomLog /var/www/example.com/logs/referer.log referer env=!INTERNAL_REFERRAL</div></td></tr></tbody></table></div>
<p>First we set an environment variable called <code>INTERNAL_REFERRAL</code> if the request comes with a referer string matching current website domain. Then we define the <code>LogFormat</code> as usual and we enable the <code>CustomLog</code> only if the environment variable is empty, thus if the request matches an external referral.</p>
<p>Related posts<ol>
<li><a href='http://www.simonecarletti.com/blog/2009/02/apache-log-regex-a-lightweight-ruby-apache-log-parser/' rel='bookmark' title='Apache Log Regex: a lightweight Ruby Apache log parser'>Apache Log Regex: a lightweight Ruby Apache log parser</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects/' rel='bookmark' title='Apache .htaccess query string redirects'>Apache .htaccess query string redirects</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/01/apache-rewriterule-and-query-string/' rel='bookmark' title='Apache RewriteRule and query string'>Apache RewriteRule and query string</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.simonecarletti.com/blog/2009/01/logging-external-referers-with-apache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache .htaccess query string redirects</title>
		<link>http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects/</link>
		<comments>http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 23:16:47 +0000</pubDate>
		<dc:creator>Simone Carletti</dc:creator>
				<category><![CDATA[Server / Apache]]></category>
		<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[redirects]]></category>

		<guid isPermaLink="false">http://www.simonecarletti.com/blog/?p=87</guid>
		<description><![CDATA[How to configure a query string based redirect for a specific page using Apache and .htaccess.]]></description>
			<content:encoded><![CDATA[<p>One of the most common question when talking about Apache and mass-redirections, is <strong>how to configure a query string based redirect for a specific page</strong>. Creating a <strong>single page redirect</strong> in Apache is as simple as writing the following line in your .htaccess file.</p>
<div class="codecolorer-container text default brush: text;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Redirect /page.php http://mydomain.site/destination.php</div></td></tr></tbody></table></div>
<p>If you need to <strong>mass-redirect a group of pages</strong> you would probably need to use the <code>RedirectMatch</code> directive.</p>
<div class="codecolorer-container text default brush: apache;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">RedirectMatch ^/oldfolder/(.*)$ http://mydomain.site/newfolder/$1</div></td></tr></tbody></table></div>
<p>This will redirect any page from the <code>oldfolder</code> to the corresponding one in <code>newfolder</code> with a convenient <strong>one-by-one redirect</strong>.</p>
<p><span id="more-87"></span>Unfortunately, either <code>Redirect</code> nor <code>RedirectMatch</code> allow you to specify a query string for the redirect source. It other words, the following statements are invalid and they will simply be ignored.</p>
<div class="codecolorer-container text default brush: apache;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Redirect /page.php?id=3 &nbsp;http://mydomain.site/page/3<br />
Redirect /page.php?id=4 &nbsp;http://mydomain.site/page/4<br />
<br />
RedirectMatch ^/page.php?id=([0-9]*)$ &nbsp;http://mydomain.site/page/$1</div></td></tr></tbody></table></div>
<p>The solution requires to change the focus from <a title="mod_alias - Apache HTTP Server" href="http://httpd.apache.org/docs/2.0/mod/mod_alias.html">mod_alias</a> to <a title="mod_rewrite - Apache HTTP Server" href="http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html">mod_rewrite</a>. Here&#8217;s an example.</p>
<div class="codecolorer-container text default brush: apache;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">RewriteEngine On<br />
RewriteCond %{REQUEST_URI} &nbsp;^/page\.php$<br />
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$<br />
RewriteRule ^(.*)$ http://mydomain.site/page/%1.pdf [R=302,L]</div></td></tr></tbody></table></div>
<p>Let me explain the solution for those who wants to learn and not only to copy.</p>
<p>The first line enables the <code>RewriteEngine</code> module. Please note that <code>mod_rewrite</code> Apache module must be installed and enabled in order to use the <code>RewriteEngine</code>.</p>
<p>The <code>RewriteCond</code> statements set all the rewrite conditions. The forth line, the real rewrite directive, will be executed <strong>if and only if all conditions are satisfied by the current request</strong>.</p>
<p>First I want to check the request is for the page I need to redirect. Skipping this condition might cause some unexpected behavior if other pages in my website are using the <code>id</code> parameter. Then I want to base the rewrite rule on the value for the current request query string. Be sure to <strong>wrap the <code>id</code> value within a regular expression match</strong> to be able to reuse the match later as a back-reference.</p>
<p>Finally I can write my redirection rule. This line looks like a <code>RedirectMatch</code> statement. First I specify the pattern for the redirection source, then the redirection target. As you can see, the value for the <code>id</code> parameter captured by the last <code>RewriteCond</code> is referenced in the target with the <code>%N</code> keyword.</p>
<p>The comma separated values at the end of the <code>RewriteRule</code> line define which flags should be applied for this rule. I want to setup a 302 Redirection and be sure Apache won&#8217;t execute any other rule after this one.</p>
<p>PS. If you suffer from &#8220;write-as-less-as-possible&#8221; sickness you might want to change the original rewrite statement with</p>
<div class="codecolorer-container text default brush: apache;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">RewriteEngine On<br />
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$<br />
RewriteRule ^page\.php$ http://mydomain.site/page/%1.pdf [R=302,L]</div></td></tr></tbody></table></div>
<p>Related posts<ol>
<li><a href='http://www.simonecarletti.com/blog/2009/01/apache-rewriterule-and-query-string/' rel='bookmark' title='Apache RewriteRule and query string'>Apache RewriteRule and query string</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/12/generic-apache-configuration-snippets/' rel='bookmark' title='Generic Apache configuration snippets'>Generic Apache configuration snippets</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/02/apache-log-regex-a-lightweight-ruby-apache-log-parser/' rel='bookmark' title='Apache Log Regex: a lightweight Ruby Apache log parser'>Apache Log Regex: a lightweight Ruby Apache log parser</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>Running Capistrano with Passenger (mod_rails)</title>
		<link>http://www.simonecarletti.com/blog/2008/12/capistrano-deploy-recipe-with-passenger-mod_rails-taste/</link>
		<comments>http://www.simonecarletti.com/blog/2008/12/capistrano-deploy-recipe-with-passenger-mod_rails-taste/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 14:45:51 +0000</pubDate>
		<dc:creator>Simone Carletti</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[mod_rails]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.simonecarletti.com/blog/?p=3</guid>
		<description><![CDATA[This recipe enables you to integrate Passenger (mod_Rails) support with Capistrano.]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-374" title="Capistrano logo" src="http://www.simonecarletti.com/blog/wp-content/uploads/2009/06/capistrano-logo.png" alt="Capistrano logo" width="150" height="57" />The following recipe enables you to <strong>deploy on a Passenger (mod_Rails) server with Capistrano</strong>. It&#8217;s a ready to use boilerplate, you just need to store it somewhere in your rails project (for example in the <code>config/deploy</code> folder) and <code>require</code> it from your <code>deploy.rb</code> file.<span id="more-3"></span></p>
<div class="codecolorer-container text default brush: ruby;" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">#<br />
# = Capistrano Passenger deploy tasks<br />
#<br />
# Provides tasks for deploying a Rails application with Passenger (aka mod_rails).<br />
#<br />
# Category:: &nbsp; &nbsp;Capistrano<br />
# Package:: &nbsp; &nbsp; Passenger<br />
# Author:: &nbsp; &nbsp; &nbsp;Simone Carletti<br />
# Copyright:: &nbsp; 2007-2008 The Authors<br />
# License:: &nbsp; &nbsp; MIT License<br />
# Link:: &nbsp; &nbsp; &nbsp; &nbsp;http://www.simonecarletti.com/<br />
# Source:: &nbsp; &nbsp; &nbsp;http://gist.github.com/2769<br />
#<br />
#<br />
<br />
unless Capistrano::Configuration.respond_to?(:instance)<br />
&nbsp; abort &quot;This extension requires Capistrano 2&quot;<br />
end<br />
<br />
Capistrano::Configuration.instance.load do<br />
<br />
&nbsp; namespace :passenger do<br />
<br />
&nbsp; &nbsp; desc &lt;&lt;-DESC<br />
&nbsp; &nbsp; &nbsp; Restarts your application. \<br />
&nbsp; &nbsp; &nbsp; This works by creating an empty `restart.txt` file in the `tmp` folder<br />
&nbsp; &nbsp; &nbsp; as requested by Passenger server.<br />
&nbsp; &nbsp; DESC<br />
&nbsp; &nbsp; task :restart, :roles =&gt; :app, :except =&gt; { :no_release =&gt; true } do<br />
&nbsp; &nbsp; &nbsp; run &quot;touch #{current_path}/tmp/restart.txt&quot;<br />
&nbsp; &nbsp; end<br />
<br />
&nbsp; &nbsp; desc &lt;&lt;-DESC<br />
&nbsp; &nbsp; &nbsp; Starts the application servers. \<br />
&nbsp; &nbsp; &nbsp; Please note that this task is not supported by Passenger server.<br />
&nbsp; &nbsp; DESC<br />
&nbsp; &nbsp; task :start, :roles =&gt; :app do<br />
&nbsp; &nbsp; &nbsp; logger.info &quot;:start task not supported by Passenger server&quot;<br />
&nbsp; &nbsp; end<br />
<br />
&nbsp; &nbsp; desc &lt;&lt;-DESC<br />
&nbsp; &nbsp; &nbsp; Stops the application servers. \<br />
&nbsp; &nbsp; &nbsp; Please note that this task is not supported by Passenger server.<br />
&nbsp; &nbsp; DESC<br />
&nbsp; &nbsp; task :stop, :roles =&gt; :app do<br />
&nbsp; &nbsp; &nbsp; logger.info &quot;:stop task not supported by Passenger server&quot;<br />
&nbsp; &nbsp; end<br />
<br />
&nbsp; end<br />
<br />
&nbsp; namespace :deploy do<br />
<br />
&nbsp; &nbsp; desc &lt;&lt;-DESC<br />
&nbsp; &nbsp; &nbsp; Restarts your application. \<br />
&nbsp; &nbsp; &nbsp; Overwrites default :restart task for Passenger server.<br />
&nbsp; &nbsp; DESC<br />
&nbsp; &nbsp; task :restart, :roles =&gt; :app, :except =&gt; { :no_release =&gt; true } do<br />
&nbsp; &nbsp; &nbsp; passenger.restart<br />
&nbsp; &nbsp; end<br />
<br />
&nbsp; &nbsp; desc &lt;&lt;-DESC<br />
&nbsp; &nbsp; &nbsp; Starts the application servers. \<br />
&nbsp; &nbsp; &nbsp; Overwrites default :start task for Passenger server.<br />
&nbsp; &nbsp; DESC<br />
&nbsp; &nbsp; task :start, :roles =&gt; :app do<br />
&nbsp; &nbsp; &nbsp; passenger.start<br />
&nbsp; &nbsp; end<br />
<br />
&nbsp; &nbsp; desc &lt;&lt;-DESC<br />
&nbsp; &nbsp; &nbsp; Stops the application servers. \<br />
&nbsp; &nbsp; &nbsp; Overwrites default :start task for Passenger server.<br />
&nbsp; &nbsp; DESC<br />
&nbsp; &nbsp; task :stop, :roles =&gt; :app do<br />
&nbsp; &nbsp; &nbsp; passenger.stop<br />
&nbsp; &nbsp; end<br />
<br />
&nbsp; end<br />
<br />
end</div></td></tr></tbody></table></div>
<p>This extension creates the following Capistrano tasks under the <code>passenger</code> namespace:</p>
<ol>
<li>start</li>
<li>stop</li>
<li>restart</li>
</ol>
<p>Additionally, it overwrites the default Capistrano <code>deploy:start/stop/restart</code> tasks to fully integrate Passenger into your current deployment strategy.</p>
<p>Please note that, due to Passenger architecture, only <code>restart</code> task is supported. <code>start</code> and <code>stop</code> task are available only for compatibility purpose. Invoking <code>deploy:start</code> or <code>deploy:stop</code> will simply return a warning.</p>
<p>The most recent version of this recipe is <a href="http://gist.github.com/3102">available as a Gist (#3102)</a>.</p>
<p>Related posts<ol>
<li><a href='http://www.simonecarletti.com/blog/2010/07/capistrano-executing-a-command-as-root-without-using-sudo/' rel='bookmark' title='Capistrano: Executing a command as root without using sudo'>Capistrano: Executing a command as root without using sudo</a></li>
<li><a href='http://www.simonecarletti.com/blog/2011/02/how-to-restart-god-when-you-deploy-a-new-release/' rel='bookmark' title='How to restart God when you deploy a new release via Capistrano'>How to restart God when you deploy a new release via Capistrano</a></li>
<li><a href='http://www.simonecarletti.com/blog/2009/02/capistrano-uploads-folder/' rel='bookmark' title='Capistrano: Managing an uploads folder'>Capistrano: Managing an uploads folder</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.simonecarletti.com/blog/2008/12/capistrano-deploy-recipe-with-passenger-mod_rails-taste/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

