<?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: .Htaccess rewrites, Mod_Rewrite Tricks and Tips</title>
	<atom:link href="http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html</link>
	<description>Advanced Web Development</description>
	<lastBuildDate>Wed, 18 Nov 2009 23:28:48 -0500</lastBuildDate>
	
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Vector Thorn</title>
		<link>http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html#comment-110180</link>
		<dc:creator>Vector Thorn</dc:creator>
		<pubDate>Wed, 18 Nov 2009 23:28:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html#comment-110180</guid>
		<description>With all the mod_rewrite articles out there that show you how to redirect a request, none of them show you how to keep the url in the address bar the same?

For example, you say you can redirect:
/somepage-1234.html

to the page:
/?somepage=1234 [R=301]


But when you do that, the user is taken to that page, and it is shown in the address bar as the dynamic page. So how to you keep the original url in the address bar?</description>
		<content:encoded><![CDATA[<p>With all the mod_rewrite articles out there that show you how to redirect a request, none of them show you how to keep the url in the address bar the same?</p>
<p>For example, you say you can redirect:<br />
/somepage-1234.html</p>
<p>to the page:<br />
/?somepage=1234 [R=301]</p>
<p>But when you do that, the user is taken to that page, and it is shown in the address bar as the dynamic page. So how to you keep the original url in the address bar?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: juan fernando</title>
		<link>http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html#comment-109098</link>
		<dc:creator>juan fernando</dc:creator>
		<pubDate>Thu, 12 Nov 2009 06:15:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html#comment-109098</guid>
		<description>I have several domains point to the same htdocs directory.
i have some static content that resides under &lt;code&gt;htdocs/domain.com/images/blah.jpg&lt;/code&gt; so how do i take a request that is &lt;code&gt;images/blah.jpg&lt;/code&gt; and properly check against &lt;code&gt;htdocs/domain.com/images/blah.jpg&lt;/code&gt; and if the file doesn&#039;t exist then go to &lt;code&gt;view.php?search=images/blah.jpg&lt;/code&gt; ? 

&lt;pre&gt;RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteCond %1/%{REQUEST_FILENAME} -f
RewriteCond %1/%{REQUEST_FILENAME} -d
RewriteRule index.php?=%{REQUEST_FILENAME} [L]&lt;/pre&gt;
</description>
		<content:encoded><![CDATA[<p>I have several domains point to the same htdocs directory.<br />
i have some static content that resides under <code>htdocs/domain.com/images/blah.jpg</code> so how do i take a request that is <code>images/blah.jpg</code> and properly check against <code>htdocs/domain.com/images/blah.jpg</code> and if the file doesn&#8217;t exist then go to <code>view.php?search=images/blah.jpg</code> ? </p>
<pre>RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteCond %1/%{REQUEST_FILENAME} -f
RewriteCond %1/%{REQUEST_FILENAME} -d
RewriteRule index.php?=%{REQUEST_FILENAME} [L]</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard</title>
		<link>http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html#comment-108849</link>
		<dc:creator>Richard</dc:creator>
		<pubDate>Tue, 10 Nov 2009 20:06:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html#comment-108849</guid>
		<description>Awesome job, this was the page that pulled all the pieces together for me.

Thanks!

Richard</description>
		<content:encoded><![CDATA[<p>Awesome job, this was the page that pulled all the pieces together for me.</p>
<p>Thanks!</p>
<p>Richard</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pilot</title>
		<link>http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html#comment-105094</link>
		<dc:creator>pilot</dc:creator>
		<pubDate>Sun, 11 Oct 2009 16:39:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html#comment-105094</guid>
		<description>&lt;p&gt;2nd Follow-up on &lt;a href=&quot;#require-no-subdomain-1&quot;&gt;REQUIRE NO SUBDOMAIN&lt;/a&gt; -- the other (first) prototype above&lt;/p&gt;

&lt;p&gt;Just a note on the other version above.  It reads:&lt;/p&gt;

&lt;pre&gt;RewriteCond %{HTTP_HOST} \.([a-z-]+\.[a-z]{2,6})$ [NC]
RewriteRule ^/(.*)$ http://%1/$1 [R=301,L]&lt;/pre&gt;

&lt;p&gt;It may be worth noting that the domain name part of the filter is missing numbers.  That is, the class &quot;&lt;code&gt;[a-z-]&lt;/code&gt;&quot; means any lower case alphabetical character and the &quot;&lt;code&gt;-&lt;/code&gt;&quot; dash symbol, but numbers can also be used in domains.  I still do not see why the forward slash is placed preceding the &lt;code&gt;$1&lt;/code&gt; in the rewrite (see earlier comments on this).  So I propose the following instead:&lt;/p&gt;

&lt;pre&gt;RewriteCond %{HTTP_HOST} \.([a-z0-9-]+\.[a-z]{2,6})$ [NC]
RewriteRule ^/(.*)$ http://%1$1 [R=301]&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>2nd Follow-up on <a href="#require-no-subdomain-1">REQUIRE NO SUBDOMAIN</a> &#8212; the other (first) prototype above</p>
<p>Just a note on the other version above.  It reads:</p>
<pre>RewriteCond %{HTTP_HOST} \.([a-z-]+\.[a-z]{2,6})$ [NC]
RewriteRule ^/(.*)$ http://%1/$1 [R=301,L]</pre>
<p>It may be worth noting that the domain name part of the filter is missing numbers.  That is, the class &#8220;<code>[a-z-]</code>&#8221; means any lower case alphabetical character and the &#8220;<code>-</code>&#8221; dash symbol, but numbers can also be used in domains.  I still do not see why the forward slash is placed preceding the <code>$1</code> in the rewrite (see earlier comments on this).  So I propose the following instead:</p>
<pre>RewriteCond %{HTTP_HOST} \.([a-z0-9-]+\.[a-z]{2,6})$ [NC]
RewriteRule ^/(.*)$ http://%1$1 [R=301]</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: pilot</title>
		<link>http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html#comment-105090</link>
		<dc:creator>pilot</dc:creator>
		<pubDate>Sun, 11 Oct 2009 16:29:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html#comment-105090</guid>
		<description>&lt;p&gt;Follow up to previous post about &lt;a href=&quot;#require-no-subdomain-2&quot;&gt;REQUIRE NO SUBDOMAIN&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have tried the following bit of code and it seems to work in every conceivable case.  I have a mixed SSL and non-SSL website with gates directing according back and forth accordingly.  The Rewrite directive with the &quot;&lt;code&gt;http://&#46;..&lt;/code&gt;&quot; doesnt cause problems, I think for the reasons I outlined in the previous post.  Also, I run some servers on nonnormal ports for SSL (i.e., not 443) but this recipe also seems to work when explicitly detailing the port in the request (i.e., &lt;code&gt;https://garbage-I-want-to-get-rid-of.myDomain.com:445/some/path&lt;/code&gt; ).  I guess the reason is that HTTP_HOST includes the port number as part of the variable and I have  &lt;strong&gt;NOT&lt;/strong&gt; excluded numbers in the second negative class of the conditional (unlike in the &lt;a href=&quot;#require-no-subdomain-2&quot;&gt;original REQUIRE NO SUBDOMAIN&lt;/a&gt; above and so they do not get rewritten.&lt;/p&gt;

&lt;p&gt;In any case, the code I am using (successfully... so far) is:&lt;/p&gt;
&lt;pre&gt;     
RewriteCond %{HTTP_HOST} \.([^.]+\.[^.]+)$
RewriteRule ^(.*)$ http://%1$1 [R=301]&lt;/pre&gt;

&lt;p&gt;Note also I have omitted the &quot;L&quot; tag -- I have and you might have further Rewrites in he same directory...&lt;/p&gt;

&lt;p&gt;Also note: per my previous note, I removed the backslash &lt;code&gt;\&lt;/code&gt; escapes from the character classes in the conditionals without problem, so I assume the original taken from here was not optimal.  For comparison, the older version I am referring to reads:&lt;/p&gt;
&lt;pre&gt;RewriteCond %{HTTP_HOST} \.([^\.]+\.[^\.0-9]+)$
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Follow up to previous post about <a href="#require-no-subdomain-2">REQUIRE NO SUBDOMAIN</a></p>
<p>I have tried the following bit of code and it seems to work in every conceivable case.  I have a mixed SSL and non-SSL website with gates directing according back and forth accordingly.  The Rewrite directive with the &#8220;<code>http://&#46;..</code>&#8221; doesnt cause problems, I think for the reasons I outlined in the previous post.  Also, I run some servers on nonnormal ports for SSL (i.e., not 443) but this recipe also seems to work when explicitly detailing the port in the request (i.e., <code>https://garbage-I-want-to-get-rid-of.myDomain.com:445/some/path</code> ).  I guess the reason is that HTTP_HOST includes the port number as part of the variable and I have  <strong>NOT</strong> excluded numbers in the second negative class of the conditional (unlike in the <a href="#require-no-subdomain-2">original REQUIRE NO SUBDOMAIN</a> above and so they do not get rewritten.</p>
<p>In any case, the code I am using (successfully&#8230; so far) is:</p>
<pre>
RewriteCond %{HTTP_HOST} \.([^.]+\.[^.]+)$
RewriteRule ^(.*)$ http://%1$1 [R=301]</pre>
<p>Note also I have omitted the &#8220;L&#8221; tag &#8212; I have and you might have further Rewrites in he same directory&#8230;</p>
<p>Also note: per my previous note, I removed the backslash <code>\</code> escapes from the character classes in the conditionals without problem, so I assume the original taken from here was not optimal.  For comparison, the older version I am referring to reads:</p>
<pre>RewriteCond %{HTTP_HOST} \.([^\.]+\.[^\.0-9]+)$
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: pilot</title>
		<link>http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html#comment-105087</link>
		<dc:creator>pilot</dc:creator>
		<pubDate>Sun, 11 Oct 2009 15:47:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html#comment-105087</guid>
		<description>&lt;p&gt;Wonderful work/tutorial!  A real pleasure to see actually how apache operates!!&lt;/p&gt;

&lt;p&gt;Question:&lt;/p&gt;
&lt;p&gt;In the second example of &lt;strong&gt;No Subdomains&lt;/strong&gt; it states:&lt;/p&gt;


&lt;blockquote cite=&quot;http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html&quot;&gt;
&lt;pre&gt;RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} \.([^\.]+\.[^\.0-9]+)$
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]&lt;/pre&gt;
&lt;/blockquote&gt;



&lt;p&gt;Why are the &quot;&lt;code&gt;.&lt;/code&gt;&quot; in the classes escaped with &lt;code&gt;\&lt;/code&gt; ?  Are not all meta characters automatically escaped in class ranges?
Why or how does the &quot;/&quot; work in the  &lt;code&gt;%1/$1&lt;/code&gt;? Does not the &lt;code&gt;$1&lt;/code&gt; already include the  &lt;code&gt;/&lt;/code&gt; ?
In the second class  &lt;q&gt;&lt;code&gt;[^\.0-9]&lt;/code&gt;&lt;/q&gt; the numbers must be there for the case where a port has been identified I assume (?), because an IP address would anyway show up with 2 or more &quot;&lt;code&gt;.&lt;/code&gt;&quot;  But then, shouldn&#039;t &quot;&lt;code&gt;:&lt;/code&gt;&quot; also be included? Or did I miss something?&lt;/p&gt;

&lt;p&gt;As an aside, I think this also works for cases where one is alternating between SSL and otherwise if (and only if) one has further rewrites to handle where the page should be encrypted.  From the tutorial I read it would seem that when authentication is processed, the returned page will be passed once through to get the domain correct, but then on the second pass will not be rewritten (as it not longer meets the conditions) and so be forced to SLL (by whatever other rewrites or redirects are present).&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Wonderful work/tutorial!  A real pleasure to see actually how apache operates!!</p>
<p>Question:</p>
<p>In the second example of <strong>No Subdomains</strong> it states:</p>
<blockquote cite="http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html">
<pre>RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} \.([^\.]+\.[^\.0-9]+)$
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]</pre>
</blockquote>
<p>Why are the &#8220;<code>.</code>&#8221; in the classes escaped with <code>\</code> ?  Are not all meta characters automatically escaped in class ranges?<br />
Why or how does the &#8220;/&#8221; work in the  <code>%1/$1</code>? Does not the <code>$1</code> already include the  <code>/</code> ?<br />
In the second class  <q><code>[^\.0-9]</code></q> the numbers must be there for the case where a port has been identified I assume (?), because an IP address would anyway show up with 2 or more &#8220;<code>.</code>&#8221;  But then, shouldn&#8217;t &#8220;<code>:</code>&#8221; also be included? Or did I miss something?</p>
<p>As an aside, I think this also works for cases where one is alternating between SSL and otherwise if (and only if) one has further rewrites to handle where the page should be encrypted.  From the tutorial I read it would seem that when authentication is processed, the returned page will be passed once through to get the domain correct, but then on the second pass will not be rewritten (as it not longer meets the conditions) and so be forced to SLL (by whatever other rewrites or redirects are present).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Samson</title>
		<link>http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html#comment-105023</link>
		<dc:creator>Samson</dc:creator>
		<pubDate>Sat, 10 Oct 2009 11:23:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html#comment-105023</guid>
		<description>I want to add the ability to put a hyphen in the subdomain. Can I do this also with .htaccess rewrite? If so how do I code this?</description>
		<content:encoded><![CDATA[<p>I want to add the ability to put a hyphen in the subdomain. Can I do this also with .htaccess rewrite? If so how do I code this?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mathguy</title>
		<link>http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html#comment-104819</link>
		<dc:creator>mathguy</dc:creator>
		<pubDate>Thu, 01 Oct 2009 16:38:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html#comment-104819</guid>
		<description>Hi,
Awesome information Please provide me the solution for the following.
I have used the following redirection code in my &lt;code&gt;.htaccess&lt;/code&gt; file which used to work fine in server where I hosted early.


&lt;pre&gt;RewriteEngine on
RewriteCond %{REQUEST_URI} ^/(.*).html
RewriteRule ^(.*).html /math-tutorial/tutor.php?name=$1 [L]&lt;/pre&gt;


The Rewrite condition  work perfectly, but not the rewrite rule. 

Thanks</description>
		<content:encoded><![CDATA[<p>Hi,<br />
Awesome information Please provide me the solution for the following.<br />
I have used the following redirection code in my <code>.htaccess</code> file which used to work fine in server where I hosted early.</p>
<pre>RewriteEngine on
RewriteCond %{REQUEST_URI} ^/(.*).html
RewriteRule ^(.*).html /math-tutorial/tutor.php?name=$1 [L]</pre>
<p>The Rewrite condition  work perfectly, but not the rewrite rule. </p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew</title>
		<link>http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html#comment-104740</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Tue, 29 Sep 2009 08:26:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html#comment-104740</guid>
		<description>I&#039;ve been trying to change php extensions to html for the last week and they simply will not abide by the rule

&lt;pre&gt;RewriteBase /
RewriteRule ^(.*)-p-(.*).html$ .php?city=$2&amp;%{QUERY_STRING}&lt;/pre&gt;


It&#039;s dring me crazy :(

Any help would be cool</description>
		<content:encoded><![CDATA[<p>I&#8217;ve been trying to change php extensions to html for the last week and they simply will not abide by the rule</p>
<pre>RewriteBase /
RewriteRule ^(.*)-p-(.*).html$ .php?city=$2&amp;%{QUERY_STRING}</pre>
<p>It&#8217;s dring me crazy :(</p>
<p>Any help would be cool</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: EJ</title>
		<link>http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html#comment-98013</link>
		<dc:creator>EJ</dc:creator>
		<pubDate>Wed, 26 Aug 2009 07:35:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html#comment-98013</guid>
		<description>Super htaccess article.
It was a good help to me.
Thanks.</description>
		<content:encoded><![CDATA[<p>Super htaccess article.<br />
It was a good help to me.<br />
Thanks.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
