<?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/"
	>

<channel>
	<title>Dyn Solutions &#187; PHP</title>
	<atom:link href="http://blog.dyn-solutions.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.dyn-solutions.com</link>
	<description>dyn's blog</description>
	<pubDate>Fri, 11 Mar 2011 17:50:47 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SEO Friendly URLs</title>
		<link>http://blog.dyn-solutions.com/2009/06/seo-friendly-urls/</link>
		<comments>http://blog.dyn-solutions.com/2009/06/seo-friendly-urls/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 23:10:47 +0000</pubDate>
		<dc:creator>dyn</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[apache]]></category>

		<category><![CDATA[seo]]></category>

		<guid isPermaLink="false">http://blog.dyn-solutions.com/?p=9</guid>
		<description><![CDATA[Let’s say you have a site which has movie reviews. To display a unique review, you would have a PHP page, for example review.php, which obtains the id of the review and shows the title and description of that review. So, if you want to see the review with id 45, you need to access [...]]]></description>
			<content:encoded><![CDATA[<p>Let’s say you have a site which has movie reviews. To display a unique review, you would have a PHP page, for example review.php, which obtains the id of the review and shows the title and description of that review. So, if you want to see the review with id 45, you need to access the following URL: http://yoursite.com/review.php?id=45</p>
<p>Do you see a problem with this? No? Are you sure?  Ok, then I’ll have to explain it. With that type of URL, you are not able to know anything about the review. It could be a review for “Casablanca” just as easily as it could a review for “Ace Ventura: Pet Detective”. And that’s not the biggest problem; it is also a bad SEO URL!</p>
<p>How can you fix this? Use SEO Friendly URLs.</p>
<p>Requirements: Apache (with mod_rewrite module) installed on your server (most hosting services already have this).</p>
<p>Step 1: Insert the following code on you PHP script</p>
<div class="codecolorer-container php blackboard" 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 /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> StrToSearchFriendlyURL<span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'page'</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000088;">$s</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">ENT_QUOTES</span><span style="color: #339933;">,</span> <span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'CHARSET'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$s</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/&amp;amp;(.)(?:acute|cedil|circ|ring|tilde|uml|grave|elig|slash);/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'\\1'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$s</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/\W+/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'_'</span><span style="color: #339933;">,</span> <span style="color: #990000;">html_entity_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$s</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/_{2,}/'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'_'</span><span style="color: #339933;">,</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$s</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'_'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$s</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'page'</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$s</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Step 2: Apply the above function to your regular URLs to make them SEO Friendy.</p>
<p>Step 3: When inserting the new URLs on your page, add a dash (-), the review id and html extension at the end.</p>
<p>Example:</p>
<div class="codecolorer-container html4strict blackboard" 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="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;{SEO_friendly_URL}-{id}.html&quot;</span>&gt;</span>{$review_title}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></div></td></tr></tbody></table></div>
<p>Step 4: Create a .htaccess file with the following content.</p>
<div class="codecolorer-container text blackboard" 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">Options +FollowSymLinks<br />
<br />
RewriteEngine On<br />
RewriteRule ^[^-]+-([0-9]+)\.html$ review.php?id=$1 [L]</div></td></tr></tbody></table></div>
<p>Step 5: Place the .htaccess file on your site’s document root.</p>
<p>That’s it! The URLs on your site will now look something like this: http://yoursite.com/casablanca-45.html which will be interpreted by Apache like http://yoursite.com/review.php?id=45</p>
<p>More about mod_rewrite: <a href="http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html">http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html</a><br />
More about .htaccess files: <a href="http://httpd.apache.org/docs/1.3/howto/htaccess.html">http://httpd.apache.org/docs/1.3/howto/htaccess.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dyn-solutions.com/2009/06/seo-friendly-urls/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

