<?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: URL rewriting using Apache</title>
	<atom:link href="http://curtistasker.com/blog/programming/109/url-rewriting-using-apache/feed" rel="self" type="application/rss+xml" />
	<link>http://curtistasker.com/blog/programming/109/url-rewriting-using-apache</link>
	<description>&#99;&#117;&#114;&#116;&#105;&#115; (at) &#116;&#97;&#115;&#107;&#101;&#114; (dot) &#110;&#101;&#116;</description>
	<lastBuildDate>Tue, 14 Apr 2009 18:37:19 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Curtis</title>
		<link>http://curtistasker.com/blog/programming/109/url-rewriting-using-apache/comment-page-1#comment-25</link>
		<dc:creator>Curtis</dc:creator>
		<pubDate>Mon, 22 Sep 2008 19:34:19 +0000</pubDate>
		<guid isPermaLink="false">http://curtistasker.com/?p=109#comment-25</guid>
		<description>&lt;h3&gt;Checking if a host has a subdomain&lt;/h3&gt;
In your example (pl.engadget.com) a simple workable pattern would be &lt;code&gt;^([^\.])+.?engadget.com$&lt;/code&gt;.  This pattern will match the subdomain as a backreference, if a subdomain exists.  From there, just use the backreference in your RewriteRule.

Now if you&#039;re checking for a &lt;strong&gt;specific&lt;/strong&gt; subdomain, the pattern is simply going to be &lt;code&gt;^pl.engadget.com$&lt;/code&gt;

&lt;h3&gt;Check the present url&#039;s path&lt;/h3&gt;
It looks like you&#039;re trying to say &#039;if the url&#039;s path text matches pattern1 or pattern2 or pattern3, then rewrite the url like so&#039;.  Now if you were requiring &lt;strong&gt;all&lt;/strong&gt; of these patterns to match &lt;strong&gt;at the same time&lt;/strong&gt;, you&#039;d use several RewriteCond statements with a closing RewriteRule.

However, in your case it seems like you&#039;re trying to perform a url rewrite on several different areas (categories, tags, pages, individual posts).  For that, the best starting point is to set up a several sets of RewriteCond and RewriteRule to handle every distinct case.  Once those are working, you can try to combine the RewriteCond patterns into something more general.

&lt;h3&gt;Solution&lt;/h3&gt;
There also seems to be a minor error in your RewriteRule.  You&#039;re using [L,QSA] at the end.  The QSA flag enables the query string append mode.  This forces apache to append to the query string instead of replacing it.

So, in your RewriteRule, it will be taking the second half of the RewriteRule and appending it onto the existing url.  Simply remove the QSA and it should work fine.


Combining all this together, a sample rule would look like so:
&lt;pre&gt;
RewriteCond %{HTTP_HOST} ^pl.engadget.com$
RewriteCond %{REQUEST_URI} ^/iphone/?.*$
RewriteRule ^iphone/tag/([^/]+)/page/([0-9999]+)/?$ /index.php?
                 a=iphonetag&amp;tag=$1&amp;postpage=$2 [L]
&lt;/pre&gt;

And translated into English, it would read as follows:  If the host of the url is pl.engadget.com AND the uri of the url starts with &lt;code&gt;/iphone&lt;/code&gt; THEN take the current url (&lt;code&gt;pl.engadget.com/iphone/tag/sampletag/page/1/&lt;/code&gt;) and rewrite the url to the form &lt;code&gt;pl.engadget.com/index.php?a=iphonetag&amp;tag=sampletag&amp;postpage=1&lt;/code&gt;.

Obviously, you&#039;re going to need to put a lot more thought than I did into how the urls for this vary, and how to best match the arguments.  Hopefully I&#039;ve started you on the right track.</description>
		<content:encoded><![CDATA[<h3>Checking if a host has a subdomain</h3>
<p>In your example (pl.engadget.com) a simple workable pattern would be <code>^([^\.])+.?engadget.com$</code>.  This pattern will match the subdomain as a backreference, if a subdomain exists.  From there, just use the backreference in your RewriteRule.</p>
<p>Now if you&#8217;re checking for a <strong>specific</strong> subdomain, the pattern is simply going to be <code>^pl.engadget.com$</code></p>
<h3>Check the present url&#8217;s path</h3>
<p>It looks like you&#8217;re trying to say &#8216;if the url&#8217;s path text matches pattern1 or pattern2 or pattern3, then rewrite the url like so&#8217;.  Now if you were requiring <strong>all</strong> of these patterns to match <strong>at the same time</strong>, you&#8217;d use several RewriteCond statements with a closing RewriteRule.</p>
<p>However, in your case it seems like you&#8217;re trying to perform a url rewrite on several different areas (categories, tags, pages, individual posts).  For that, the best starting point is to set up a several sets of RewriteCond and RewriteRule to handle every distinct case.  Once those are working, you can try to combine the RewriteCond patterns into something more general.</p>
<h3>Solution</h3>
<p>There also seems to be a minor error in your RewriteRule.  You&#8217;re using [L,QSA] at the end.  The QSA flag enables the query string append mode.  This forces apache to append to the query string instead of replacing it.</p>
<p>So, in your RewriteRule, it will be taking the second half of the RewriteRule and appending it onto the existing url.  Simply remove the QSA and it should work fine.</p>
<p>Combining all this together, a sample rule would look like so:</p>
<pre>
RewriteCond %{HTTP_HOST} ^pl.engadget.com$
RewriteCond %{REQUEST_URI} ^/iphone/?.*$
RewriteRule ^iphone/tag/([^/]+)/page/([0-9999]+)/?$ /index.php?
                 a=iphonetag&#038;tag=$1&#038;postpage=$2 [L]
</pre>
<p>And translated into English, it would read as follows:  If the host of the url is pl.engadget.com AND the uri of the url starts with <code>/iphone</code> THEN take the current url (<code>pl.engadget.com/iphone/tag/sampletag/page/1/</code>) and rewrite the url to the form <code>pl.engadget.com/index.php?a=iphonetag&#038;tag=sampletag&#038;postpage=1</code>.</p>
<p>Obviously, you&#8217;re going to need to put a lot more thought than I did into how the urls for this vary, and how to best match the arguments.  Hopefully I&#8217;ve started you on the right track.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lokesh</title>
		<link>http://curtistasker.com/blog/programming/109/url-rewriting-using-apache/comment-page-1#comment-24</link>
		<dc:creator>Lokesh</dc:creator>
		<pubDate>Fri, 19 Sep 2008 07:21:23 +0000</pubDate>
		<guid isPermaLink="false">http://curtistasker.com/?p=109#comment-24</guid>
		<description>Hey
  Rewrite Conditons
  How do i check if my host has a subdomain (pl from pl.engadget.com)
  and
  How do i check if the present url&#039;s path text (/iphone/ or /iphone from pl.engadget.com/iphone or pl.engadget.com/iphone#blahhh or pl.engadget.com/iphone/whatever/stuff/here/....)

  One more thing is, if the above condtions are true, the pagination URL should be http://pl.engadget.com/iphone/page/pagenum and my htaccess I though of is;
RewriteRule ^iphone/tag/([^/]+)/page/([0-9999]+)/?$ /index.php?a=iphone-tag&amp;tag=$1&amp;postpage=$2 [L,QSA]

nothing seems to workk. please help</description>
		<content:encoded><![CDATA[<p>Hey<br />
  Rewrite Conditons<br />
  How do i check if my host has a subdomain (pl from pl.engadget.com)<br />
  and<br />
  How do i check if the present url&#8217;s path text (/iphone/ or /iphone from pl.engadget.com/iphone or pl.engadget.com/iphone#blahhh or pl.engadget.com/iphone/whatever/stuff/here/&#8230;.)</p>
<p>  One more thing is, if the above condtions are true, the pagination URL should be <a href="http://pl.engadget.com/iphone/page/pagenum" rel="nofollow">http://pl.engadget.com/iphone/page/pagenum</a> and my htaccess I though of is;<br />
RewriteRule ^iphone/tag/([^/]+)/page/([0-9999]+)/?$ /index.php?a=iphone-tag&amp;tag=$1&amp;postpage=$2 [L,QSA]</p>
<p>nothing seems to workk. please help</p>
]]></content:encoded>
	</item>
</channel>
</rss>
