<?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>My Galagzee! &#187; mod_rewrite</title>
	<atom:link href="http://my.galagzee.com/tag/mod_rewrite/feed/" rel="self" type="application/rss+xml" />
	<link>http://my.galagzee.com</link>
	<description>Tech in a Galagzee, Not So Far Away.</description>
	<lastBuildDate>Fri, 20 Jan 2012 18:46:41 +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>Apache mod_rewrite: one RewriteCond to many RewriteRules</title>
		<link>http://my.galagzee.com/2009/02/11/mod_rewrite-one-rewritecond-to-many-rewriterules/</link>
		<comments>http://my.galagzee.com/2009/02/11/mod_rewrite-one-rewritecond-to-many-rewriterules/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 03:21:56 +0000</pubDate>
		<dc:creator>Ville Walveranta</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[one RewriteCond many RewriteRules]]></category>

		<guid isPermaLink="false">http://my.galagzee.com/?p=172</guid>
		<description><![CDATA[Today I decided to resolve a problem in an Apache virtual container rewrites I&#8217;d been having for a while. It appeared that RewriteCond was &#8220;leaking&#8221;.  However, on closer observation (and lots of Googling) it turned out that RewriteCond only applies &#8230; <a href="http://my.galagzee.com/2009/02/11/mod_rewrite-one-rewritecond-to-many-rewriterules/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Today I decided to resolve a problem in an Apache virtual container rewrites I&#8217;d been having for a while. It appeared that RewriteCond was &#8220;leaking&#8221;.  However, on closer observation (and lots of Googling) it turned out that RewriteCond only applies <em>one </em>RewriteRule that comes immediately after the RewriteCond. I didn&#8217;t know that (or I had forgotten it). Either way, it didn&#8217;t seem like such a great idea to have to duplicate a lengthy RewriteCond definition half a dozen times for multiple RewriteRules in each group which there are ten (that would&#8217;ve been almost hundred duplications – not fun to maintain when the rules change).</p>
<p>Turns out there is a fairly simple trick to achieve exactly what I was looking for: if the RewriteCond is negated and followed by <strong>RewriteRule . &#8211; [S=n]</strong> to skip following <em>n</em> rules, the RewriteRules in essence are only applied when the singular RewriteCond is true. Like so:</p>
<pre class="brush: plain; title: ; notranslate">
RewriteCond %{REQUEST_URI} !^/(pattern1|pattern2|pattern3)(/[0-9]+|/P[0-9]+|)[/]?$ [NC]
RewriteRule . - [S=3]
RewriteRule ^/([^/]*)[/]?$ /index.php/site_embeds/department/$1/X [L]
RewriteRule ^/([^/]*)/([0-9]+)[/]?$ /index.php/site_embeds/article/$2/$1 [L]
RewriteRule ^/([^/]*)/P([0-9]+)[/]?$ /index.php/site_embeds/department_archive/P$2/$1 [L]
</pre>
<p>Now the last three rules are skipped if the condition is <em>not</em> true or, in reverse: they <em>are</em> applied if the condition <em>is </em>true. In other words, exactly what I was looking for!</p>
]]></content:encoded>
			<wfw:commentRss>http://my.galagzee.com/2009/02/11/mod_rewrite-one-rewritecond-to-many-rewriterules/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

