<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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>Comments on: Rewriting for SEO-Friendly URLs: .htaccess or PHP?</title>
	<atom:link href="http://pumka.net/2009/12/30/rewriting-for-seo-friendly-urls-htaccess-or-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://pumka.net/2009/12/30/rewriting-for-seo-friendly-urls-htaccess-or-php/</link>
	<description>Project Workshop</description>
	<lastBuildDate>Mon, 20 Feb 2012 21:43:21 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: Anton Oliinyk</title>
		<link>http://pumka.net/2009/12/30/rewriting-for-seo-friendly-urls-htaccess-or-php/comment-page-1/#comment-1009</link>
		<dc:creator>Anton Oliinyk</dc:creator>
		<pubDate>Mon, 20 Feb 2012 21:43:21 +0000</pubDate>
		<guid isPermaLink="false">http://blog.pumka.net/?p=207#comment-1009</guid>
		<description>Definitely, nothing changed with list().

I believe, you have to go back to my original code as it is:
list($path) = explode(‘?’, $_SERVER[&#039;REQUEST_URI&#039;]);
As you changed it the path now actually goes to your $root variable.</description>
		<content:encoded><![CDATA[<p>Definitely, nothing changed with list().</p>
<p>I believe, you have to go back to my original code as it is:<br />
list($path) = explode(‘?’, $_SERVER['REQUEST_URI']);<br />
As you changed it the path now actually goes to your $root variable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anton Oliinyk</title>
		<link>http://pumka.net/2009/12/30/rewriting-for-seo-friendly-urls-htaccess-or-php/comment-page-1/#comment-1008</link>
		<dc:creator>Anton Oliinyk</dc:creator>
		<pubDate>Mon, 20 Feb 2012 21:29:10 +0000</pubDate>
		<guid isPermaLink="false">http://blog.pumka.net/?p=207#comment-1008</guid>
		<description>&lt;blockquote&gt;what im hoping to have is the url rewritten to this automatically
wolfdogg.org/iditarod/idit_weather
without changing all my links in the source code&lt;/blockquote&gt;

Rewriting incoming request URL and generating link URLs for rendering on web pages are two different things (yet related of course).
I believe, you have no automatic way if you have URLs hardcoded. You might filter HTML output to replace URLs on-fly but it&#039;s too tricky and will drain system resources.
I suggest encapsulating URL generation into a function or better a class so that you can edit it from single place in future.

Learning MVC best practices also might help. I especially like how Zend Framework handles it as it uses the same class set for parsing incoming request URL as well as for generating URLs of links on pages.</description>
		<content:encoded><![CDATA[<blockquote><p>what im hoping to have is the url rewritten to this automatically<br />
wolfdogg.org/iditarod/idit_weather<br />
without changing all my links in the source code</p></blockquote>
<p>Rewriting incoming request URL and generating link URLs for rendering on web pages are two different things (yet related of course).<br />
I believe, you have no automatic way if you have URLs hardcoded. You might filter HTML output to replace URLs on-fly but it&#8217;s too tricky and will drain system resources.<br />
I suggest encapsulating URL generation into a function or better a class so that you can edit it from single place in future.</p>
<p>Learning MVC best practices also might help. I especially like how Zend Framework handles it as it uses the same class set for parsing incoming request URL as well as for generating URLs of links on pages.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wolfdogg</title>
		<link>http://pumka.net/2009/12/30/rewriting-for-seo-friendly-urls-htaccess-or-php/comment-page-1/#comment-1007</link>
		<dc:creator>wolfdogg</dc:creator>
		<pubDate>Mon, 20 Feb 2012 20:34:56 +0000</pubDate>
		<guid isPermaLink="false">http://blog.pumka.net/?p=207#comment-1007</guid>
		<description>i think the reason i was having hard time was because were talking about 2 different types of url querys,
i need a solution for this type of url

wolfdogg.org/?section=iditarod&amp;subject=idit_weather

i dont use the work index.php, but i want the code to be cross compatible for both /? and /index.php?  

and i need to figure out a system whats the best way to utilize those vars.  currently, &#039;section&#039; is the first subdirectory and &#039;subject&#039; is the page , in this case, wolfdogg.org/iditarod/idit_weather.php

any suggestions on how to modify the code to adapt?

curently using 

RewriteEngine On
			RewriteCond %{REQUEST_FILENAME} !-d
			RewriteCond %{REQUEST_FILENAME} !-f
			RewriteRule . index.php [L,QSA]

list($root,$path) = explode(&#039;?&#039;, $_SERVER[&#039;REQUEST_URI&#039;]);
//Explode path to directories and remove empty items:
			$pathInfo = array();
			
			foreach (explode(&#039;&amp;&#039;, $path) as $dir) {
				if (!empty($dir)) {
					$pathInfo[] = urldecode($dir);
				}
			}

looks like a good start
var dump looks like this

array(2) { [0]=&gt; string(16) &quot;section=iditarod&quot; [1]=&gt; string(20) &quot;subject=idit_weather&quot; }

what im hoping to have is the url rewritten to this automatically

wolfdogg.org/iditarod/idit_weather

without changing all my links in the source code</description>
		<content:encoded><![CDATA[<p>i think the reason i was having hard time was because were talking about 2 different types of url querys,<br />
i need a solution for this type of url</p>
<p>wolfdogg.org/?section=iditarod&amp;subject=idit_weather</p>
<p>i dont use the work index.php, but i want the code to be cross compatible for both /? and /index.php?  </p>
<p>and i need to figure out a system whats the best way to utilize those vars.  currently, &#8216;section&#8217; is the first subdirectory and &#8216;subject&#8217; is the page , in this case, wolfdogg.org/iditarod/idit_weather.php</p>
<p>any suggestions on how to modify the code to adapt?</p>
<p>curently using </p>
<p>RewriteEngine On<br />
			RewriteCond %{REQUEST_FILENAME} !-d<br />
			RewriteCond %{REQUEST_FILENAME} !-f<br />
			RewriteRule . index.php [L,QSA]</p>
<p>list($root,$path) = explode(&#8216;?&#8217;, $_SERVER['REQUEST_URI']);<br />
//Explode path to directories and remove empty items:<br />
			$pathInfo = array();</p>
<p>			foreach (explode(&#8216;&amp;&#8217;, $path) as $dir) {<br />
				if (!empty($dir)) {<br />
					$pathInfo[] = urldecode($dir);<br />
				}<br />
			}</p>
<p>looks like a good start<br />
var dump looks like this</p>
<p>array(2) { [0]=&gt; string(16) &#8220;section=iditarod&#8221; [1]=&gt; string(20) &#8220;subject=idit_weather&#8221; }</p>
<p>what im hoping to have is the url rewritten to this automatically</p>
<p>wolfdogg.org/iditarod/idit_weather</p>
<p>without changing all my links in the source code</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wolfdogg</title>
		<link>http://pumka.net/2009/12/30/rewriting-for-seo-friendly-urls-htaccess-or-php/comment-page-1/#comment-1006</link>
		<dc:creator>wolfdogg</dc:creator>
		<pubDate>Mon, 20 Feb 2012 20:19:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.pumka.net/?p=207#comment-1006</guid>
		<description>am i missing something here, because im having better luck with this

if(!empty($_SERVER[&#039;QUERY_STRING&#039;])){
				list($root,$path) = explode(&#039;?&#039;, $_SERVER[&#039;REQUEST_URI&#039;]);

//rest of code here

have they changed the functionality of list()?  because when i run it as suggested the script path is already stripped, and when the substr strips it even further, i end up with &quot;ndex.php&quot;

see var dumps for $path and $pathInfo  below

string(10) &quot;/index.php&quot; 
array(1) { [0]=&gt; string(8) &quot;ndex.php&quot; }</description>
		<content:encoded><![CDATA[<p>am i missing something here, because im having better luck with this</p>
<p>if(!empty($_SERVER['QUERY_STRING'])){<br />
				list($root,$path) = explode(&#8216;?&#8217;, $_SERVER['REQUEST_URI']);</p>
<p>//rest of code here</p>
<p>have they changed the functionality of list()?  because when i run it as suggested the script path is already stripped, and when the substr strips it even further, i end up with &#8220;ndex.php&#8221;</p>
<p>see var dumps for $path and $pathInfo  below</p>
<p>string(10) &#8220;/index.php&#8221;<br />
array(1) { [0]=&gt; string(8) &#8220;ndex.php&#8221; }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anton Oliinyk</title>
		<link>http://pumka.net/2009/12/30/rewriting-for-seo-friendly-urls-htaccess-or-php/comment-page-1/#comment-857</link>
		<dc:creator>Anton Oliinyk</dc:creator>
		<pubDate>Sun, 20 Nov 2011 15:21:53 +0000</pubDate>
		<guid isPermaLink="false">http://blog.pumka.net/?p=207#comment-857</guid>
		<description>Yes, you&#039;re right. Definitely some way is needed to establish a match between human-friendly URL directory names and database records. So &quot;slug&quot; fields do.
The only little difference in this particular sample case is that product slug have to be unique within category only as we use both category and product slugs to find a product. So there could be products with the same slug in other categories.</description>
		<content:encoded><![CDATA[<p>Yes, you&#8217;re right. Definitely some way is needed to establish a match between human-friendly URL directory names and database records. So &#8220;slug&#8221; fields do.<br />
The only little difference in this particular sample case is that product slug have to be unique within category only as we use both category and product slugs to find a product. So there could be products with the same slug in other categories.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Speedt_ouch</title>
		<link>http://pumka.net/2009/12/30/rewriting-for-seo-friendly-urls-htaccess-or-php/comment-page-1/#comment-852</link>
		<dc:creator>Speedt_ouch</dc:creator>
		<pubDate>Sat, 19 Nov 2011 23:24:21 +0000</pubDate>
		<guid isPermaLink="false">http://blog.pumka.net/?p=207#comment-852</guid>
		<description>Hi.
So I figure the slug field would be the same thing has the numeric ID field, only that contains words.
Making sure there are no duplicate slag names also.
Ill give it a try.

Thanks for the example.</description>
		<content:encoded><![CDATA[<p>Hi.<br />
So I figure the slug field would be the same thing has the numeric ID field, only that contains words.<br />
Making sure there are no duplicate slag names also.<br />
Ill give it a try.</p>
<p>Thanks for the example.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anton Oliinyk</title>
		<link>http://pumka.net/2009/12/30/rewriting-for-seo-friendly-urls-htaccess-or-php/comment-page-1/#comment-844</link>
		<dc:creator>Anton Oliinyk</dc:creator>
		<pubDate>Thu, 17 Nov 2011 18:42:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.pumka.net/?p=207#comment-844</guid>
		<description>Say, category table is:
id, slug, label
1, appliances, Appliances
2, network, Network
3, video, Video
...

And product table is:
id, category_id, slug, label, description
1, 1, blender, Blender, This is cool blender
2, 1, water-filter, Water Filter, This is cool water filter
3, 2, router, D-Link DIR-300, This is not so cool network router
...

Now you get request for /products/network/router.html 
which is rewritten to products.php?category=network&amp;product=router

Now let&#039;s query product data:
&lt;code&gt;
$rs = $db-&gt;query(&quot;
    SELECT `product`.* FROM `product`
    JOIN `category` ON `product`.`category_id` = `category`.`id` 
    WHERE `product`.`slug` = &#039;{$db-&gt;real_escape_string($_GET[&#039;product&#039;])}&#039; AND `category-&gt;slug` = &#039;{$db-&gt;real_escape_string($_GET[&#039;category&#039;])}&#039;&quot;);
&lt;/code&gt;

The result set will contain single record for the product with ID 3.

Hope that helps.</description>
		<content:encoded><![CDATA[<p>Say, category table is:<br />
id, slug, label<br />
1, appliances, Appliances<br />
2, network, Network<br />
3, video, Video<br />
&#8230;</p>
<p>And product table is:<br />
id, category_id, slug, label, description<br />
1, 1, blender, Blender, This is cool blender<br />
2, 1, water-filter, Water Filter, This is cool water filter<br />
3, 2, router, D-Link DIR-300, This is not so cool network router<br />
&#8230;</p>
<p>Now you get request for /products/network/router.html<br />
which is rewritten to products.php?category=network&#038;product=router</p>
<p>Now let&#8217;s query product data:<br />
<code><br />
$rs = $db->query("<br />
    SELECT `product`.* FROM `product`<br />
    JOIN `category` ON `product`.`category_id` = `category`.`id`<br />
    WHERE `product`.`slug` = '{$db->real_escape_string($_GET['product'])}' AND `category->slug` = '{$db->real_escape_string($_GET['category'])}'");<br />
</code></p>
<p>The result set will contain single record for the product with ID 3.</p>
<p>Hope that helps.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Speedt_ouch</title>
		<link>http://pumka.net/2009/12/30/rewriting-for-seo-friendly-urls-htaccess-or-php/comment-page-1/#comment-843</link>
		<dc:creator>Speedt_ouch</dc:creator>
		<pubDate>Thu, 17 Nov 2011 16:09:13 +0000</pubDate>
		<guid isPermaLink="false">http://blog.pumka.net/?p=207#comment-843</guid>
		<description>Hi,
Thanks for the reply.
Could you kindly provide an example please?

I would like to keep the &quot;fake URL&quot; with out any numeric values.</description>
		<content:encoded><![CDATA[<p>Hi,<br />
Thanks for the reply.<br />
Could you kindly provide an example please?</p>
<p>I would like to keep the &#8220;fake URL&#8221; with out any numeric values.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anton Oliinyk</title>
		<link>http://pumka.net/2009/12/30/rewriting-for-seo-friendly-urls-htaccess-or-php/comment-page-1/#comment-842</link>
		<dc:creator>Anton Oliinyk</dc:creator>
		<pubDate>Thu, 17 Nov 2011 15:32:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.pumka.net/?p=207#comment-842</guid>
		<description>Hi!
You&#039;ll have to query database using string IDs you use in URLs. Say, you can add a field &#039;slug&#039; to category and product tables and look up records by that field.</description>
		<content:encoded><![CDATA[<p>Hi!<br />
You&#8217;ll have to query database using string IDs you use in URLs. Say, you can add a field &#8216;slug&#8217; to category and product tables and look up records by that field.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Speedt_ouch</title>
		<link>http://pumka.net/2009/12/30/rewriting-for-seo-friendly-urls-htaccess-or-php/comment-page-1/#comment-841</link>
		<dc:creator>Speedt_ouch</dc:creator>
		<pubDate>Thu, 17 Nov 2011 14:25:16 +0000</pubDate>
		<guid isPermaLink="false">http://blog.pumka.net/?p=207#comment-841</guid>
		<description>Hi,
Thanks for sharing this.
I have some questions I hope you can clarify.

I normally user rewrite mod with the unique numeric ID of the information I need, in order to query the mysql database.
With your example there is no numeric ID.
Now I&#039;m confused :)
There is where my questions start.

Imagine I have a product
products.php?category=network&amp;product=1
products.php?category=network&amp;product=2

How can I make 
/products/network/router.html open products.php?category=network&amp;product=1
and 
/products/network/cable.html open products.php?category=network&amp;product=2

Thanks in advance</description>
		<content:encoded><![CDATA[<p>Hi,<br />
Thanks for sharing this.<br />
I have some questions I hope you can clarify.</p>
<p>I normally user rewrite mod with the unique numeric ID of the information I need, in order to query the mysql database.<br />
With your example there is no numeric ID.<br />
Now I&#8217;m confused <img src='http://pumka.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
There is where my questions start.</p>
<p>Imagine I have a product<br />
products.php?category=network&amp;product=1<br />
products.php?category=network&amp;product=2</p>
<p>How can I make<br />
/products/network/router.html open products.php?category=network&amp;product=1<br />
and<br />
/products/network/cable.html open products.php?category=network&amp;product=2</p>
<p>Thanks in advance</p>
]]></content:encoded>
	</item>
</channel>
</rss>

