<?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>Eric Ditmer &#187; .htaccess</title>
	<atom:link href="http://www.ericditmer.com/category/htaccess/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ericditmer.com</link>
	<description>ericditmer.com</description>
	<lastBuildDate>Tue, 08 Nov 2011 14:35:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Getting Started With mod_rewrite</title>
		<link>http://www.ericditmer.com/getting-started-with-mod-rewrite</link>
		<comments>http://www.ericditmer.com/getting-started-with-mod-rewrite#comments</comments>
		<pubDate>Tue, 06 Sep 2011 01:29:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.htaccess]]></category>

		<guid isPermaLink="false">http://www.ericditmer.com/?p=86</guid>
		<description><![CDATA[What is mod_rewrite? First of all, let&#8217;s get things straight: mod_rewrite is your friend. It is also an Apache module that rewrites URL&#8217;s at the server level. If you&#8217;re reading this, I&#8217;m going to assume you&#8217;ve already enabled mod_rewrite on your server. If not, there&#8217;s plenty of tutorials to show you how to enable it. [...]]]></description>
			<content:encoded><![CDATA[<h3>What is mod_rewrite?</h3>
<p>First of all, let&#8217;s get things straight: <b>mod_rewrite is your friend</b>. It is also an Apache module that rewrites URL&#8217;s at the server level. If you&#8217;re reading this, I&#8217;m going to assume you&#8217;ve already enabled mod_rewrite on your server. If not, there&#8217;s plenty of <a href="http://www.tutorio.com/tutorial/enable-mod-rewrite-on-apache" target="_blank">tutorials</a> to show you how to enable it. All set? Okay, let&#8217;s go!<br />
<span id="more-86"></span></p>
<h3>Simple mod_rewrite Example</h3>
<p>We&#8217;ll be starting with a simple mod_rewrite example just to get your feet wet. All rewrite rules follow a particular structure: <i>RewriteRule Pattern Substitution [OptionalFlags]</i><br />This example will redirect <u>http://www.example.com/foo.html</u> to <u>http://www.example.com/bar.html</u>. This can be accomplished by creating an .htaccess file and inserting the following:</p>
<pre name="code" class="html">
&lt;?php
RewriteEngine on
RewriteRule ^foo.html$ bar.html
?>
</pre>
<p>Visiting <u>http://www.example.com/foo.html</u> will now redirect you to <u>http://www.example.com/bar.html</u>. However, notice that the URL still displays <u>foo.html</u>. If you&#8217;d prefer the browser to visibly redirect to the new page, you&#8217;ll need to make a couple changes to your .htaccess file:</p>
<pre name="code" class="html">
&lt;?php
RewriteEngine on
RewriteRule ^foo.html$ http://www.example.com/bar.html [R]
?>
</pre>
<p>You&#8217;ll notice that I&#8217;ve added an [R] flag to the end of the rewrite rule. This tells the browser to visibly redirect to the new page. Also, I had to write out the full URL of the page that I&#8217;m redirecting to. If the page you&#8217;re redirecting to happens to fall within the root directory of the same site, you can simply write <u>/page.html</u> instead of the full URL.</p>
<h3>Fancy Schmancy Redirect</h3>
<p>This example is going to show you how to make your URL&#8217;s pretty. I&#8217;m talking prettier than Halle Berry. Let&#8217;s start off with an example:</p>
<pre name="code" class="html">
&lt;?php
RewriteEngine On
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?category=$1&#038;product=$2 [L]
?>
</pre>
<p>With a rewrite rule like this in place, <u>http://www.example.com/nestle/quik</u> effectively redirects to <u>http://www.example.com/index.php?category=nestle&#038;product=quik</u>. I&#8217;m going to break this rewrite rule out into multiple parts, seeing how it&#8217;s a bit more complicated than the first example:</p>
<ol>
<li><b><u>^([^/\.]+)/([^/\.]+)/?$</u></b> &#8211; This pattern returns two variables, separated by a forward-slash. The two variables can contain any characters that aren&#8217;t a forward-slash or a period.</li>
<li><b><u>$1.php</u></b> &#8211; This is the page that you&#8217;ll be redirected to. $1 and $2 will be replaced with the previously captured data, respectively.</li>
<li><b><u>[L]</u></b> &#8211; This optional flag tells Apache to stop processing rewrite rules after this point.</li>
</ol>
<p>Well, I hope this wasn&#8217;t too overwhelming. This is just scratching the surface of mod_rewrite. Remember though, once you&#8217;ve got mod_rewrite down, all the ladies will constantly swarm you. Okay, that might not be true, but it will definitely save you a few headaches.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ericditmer.com/getting-started-with-mod-rewrite/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

