<?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>arkinEx Codex &#187; navigation</title>
	<atom:link href="http://www.arkinex.com/contains/navigation/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.arkinex.com</link>
	<description>the place where all my code can be viewed</description>
	<lastBuildDate>Wed, 04 Nov 2009 20:39:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Advanced Navigation II using Clean Urls</title>
		<link>http://www.arkinex.com/php/tutorials/8/navigation-using-clean-urls-htaccess/</link>
		<comments>http://www.arkinex.com/php/tutorials/8/navigation-using-clean-urls-htaccess/#comments</comments>
		<pubDate>Thu, 01 Nov 2007 21:36:59 +0000</pubDate>
		<dc:creator>arkin</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[seo]]></category>

		<guid isPermaLink="false">http://www.arkinex.com/php/tutorials/8/navigation-using-clean-urls-htaccess/</guid>
		<description><![CDATA[This tutorial will teach you how to implement clean SEO friendly web URLs. Example: Turning /index.php?page=register into http://www.domain.com/register/. First things first, lets explain what SEO friendly web URLs can do. They promote traffic as /home/ is easier to remember than index.php?page=home They are easier for search engines to crawl, some search engines refuse to crawl [...]]]></description>
			<content:encoded><![CDATA[<p>This tutorial will teach you how to implement clean SEO friendly web URLs.<br />
<strong>Example</strong>: Turning /index.php?page=<strong>register</strong> into http://www.domain.com<strong>/register/</strong>.</p>
<p><span id="more-8"></span>First things first, lets explain what SEO friendly web URLs can do.</p>
<ol>
<li>They promote traffic as /home/ is easier to remember than index.php?page=home</li>
<li>They are easier for search engines to crawl, some search engines refuse to crawl anything after the ?</li>
<li>They are easier to maintain and keep permanent (even if you update your scripts).</li>
<li>They hide the chosen programming language from the visiting users.</li>
</ol>
<p>All you require is an Apache webserver (common among webhosts) &amp; a basic knowledge of PHP.<br />
Lets take a look at my first example, create a file called &#8216;<strong>.htaccess</strong>&#8216; (period then htaccess):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># These hashes are comments, they will explain what I am doing.</span>
<span style="color: #666666; font-style: italic;"># First things first, lets turn on the Rewrite Engine</span>
RewriteEngine On
<span style="color: #666666; font-style: italic;"># Then lets define some rules</span>
RewriteRule ^<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>a-z0-<span style="color: #000000;">9</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span>$ <span style="color: #000000; font-weight: bold;">/</span>index.php?<span style="color: #007800;">page</span>=$<span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>NC,L<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>The brackets/parenthesis are used to start a variable, variables are stored in order and are numeric, this is used and referred to later in the Rule using a <strong>$1</strong>. The <strong>[a-z0-9]</strong> signifies it can be any alphabetic or numeric character, and the plus<strong>+</strong> symbol means it has to be more than one character long.  I used a-z0-9 instead of a global (.*) which matches anything because I consider it more secure.</p>
<p>The ^ and $ are a standard regular expression and signify beginning and end, so the user cannot add anything else, (aka. /home/blaaaa would be invalid) and the index.php?page=$1 points back to index.php. At the end of the line, parameters or options are defined. In this case <strong>NC</strong> stands for <strong>Case InSensItIvE</strong> and the <strong>L</strong> stands for <strong>Last Rule</strong>, so if that rule is triggered, no others are.</p>
<p>This example turns http://www.domain.com/downloads/ into http://www.domain.com/index.php?page=downloads.<br />
If you would like to read up on <strong>index.php?page=</strong> methods, please review &#8220;<a href="http://arkinex.psycholz.com/2007/09/15/advanced-navigation-using-includes/" rel="bookmark" title="Permanent Link to ">Advanced Navigation using Includes</a>&#8220;.</p>
<p>Other resources I found useful:</p>
<ul>
<li><a href="http://www.ilovejackdaniels.com/cheat-sheets/mod_rewrite-cheat-sheet/" title="ILoveJackDaniels Mod_Rewrite Cheat Sheet" target="_blank">Mod Rewrite Cheat Sheet</a> (Great to print out)</li>
<li><a href="http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html" title="Apache 2.2 Mod_Rewrite Documentation" target="_blank">Apache docs on Mod Rewrite</a> (For the more advanced)</li>
</ul>
<p>Hope you enjoyed this tutorial.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arkinex.com/php/tutorials/8/navigation-using-clean-urls-htaccess/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Advanced Navigation using Includes</title>
		<link>http://www.arkinex.com/php/tutorials/4/advanced-navigation-using-includes/</link>
		<comments>http://www.arkinex.com/php/tutorials/4/advanced-navigation-using-includes/#comments</comments>
		<pubDate>Sat, 15 Sep 2007 07:33:05 +0000</pubDate>
		<dc:creator>arkin</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[include]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://arkinex.psycholz.com/2007/09/15/advanced-navigation-using-includes/</guid>
		<description><![CDATA[A very simple way of doing the index.php?page=page_here. Includes a few configuration options. Written in php4, works in php5, mostly so you can view the source and attempt at understanding how it works. /*--- Configuration ---*/ &#160; $page = Array&#40;&#41;; &#160; // Edit these vars or leave as is. &#160; $page&#91;'home'&#93; = &#34;home&#34;; &#160; // [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/resources/post-preview-thumbs/sml-070915-php-nav.jpg" alt="PHP Navigation tutorial" align="right" />A very simple way of doing the index.php?page=<strong>page_here</strong>. Includes a few configuration options.</p>
<p>Written in php4, works in php5, mostly so you can view the source and attempt at understanding how it works.</p>
<p><span id="more-4"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*--- Configuration ---*/</span>
&nbsp;
<span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #990000;">Array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Edit these vars or leave as is.</span>
&nbsp;
<span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'home'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;home&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Replace this with the default or main page.</span>
&nbsp;
<span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;404&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Replace this with the 404 page, can be 'home' also or even $page['home'].</span>
&nbsp;
<span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'format'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;.php&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// This will be the format of your page so ?page=bla will be bla.php.</span>
&nbsp;
<span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'trig'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;page&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// The trigger used so ?page=bla.</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*--- Do not edit below! ---*/</span><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'trig'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000088;">$pg</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'home'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'format'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">ctype_alpha</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'trig'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'trig'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'format'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000088;">$pg</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'format'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000088;">$pg</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'trig'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'format'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pg</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><a href="http://php.net/ctype_alpha" title="PHP Function: ctype_alpha" target="_blank"> ctype_alpha</a>  is used to make sure the &#8220;page&#8221; passed by the user only contains characters A-Z for security (so people can&#8217;t include /etc/passwd for example).</p>
<p><a href="http://www.php.net/file_exists" title="PHP Function: file_exists" target="_blank">file_exists</a> is used to determine whether the page + extension actually exist and if they don&#8217;t, the error page is then thrown.</p>
<p>An idea, if you want a readable page name from $pg, you could try</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$page_name</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ucwords</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pg</span><span style="color: #339933;">,</span>  <span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'format'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If you have any further questions, please do not hesitate to leave a comment,<br />
I will update this snippet when features are suggested or questions and comments made.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arkinex.com/php/tutorials/4/advanced-navigation-using-includes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
