<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: Can you help me with a mod_rewrite problem...?</title>
	<link>http://ask.metafilter.com/126868/Can-you-help-me-with-a-modrewrite-problem/</link>
	<description>Comments on Ask MetaFilter post Can you help me with a mod_rewrite problem...?</description>
	<pubDate>Wed, 08 Jul 2009 09:38:58 -0800</pubDate>
	<lastBuildDate>Wed, 08 Jul 2009 09:38:58 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: Can you help me with a mod_rewrite problem...?</title>
		<link>http://ask.metafilter.com/126868/Can-you-help-me-with-a-modrewrite-problem</link>	
		<description>Can you help me with a mod_rewrite problem...? &lt;br /&gt;&lt;br /&gt; I have two servers with copies of the same code on them. Lets call them www.example.com and test.example.com&lt;br&gt;
&lt;br&gt;
on www.example.com the files are in the directory /var/www/html/thesite&lt;br&gt;
&lt;br&gt;
on test.example.com the files are in the directory /var/www/html/stupidteststructure/anotherdir/thesite_test&lt;br&gt;
&lt;br&gt;
Sadly, I can&apos;t do anything about this.&lt;br&gt;
&lt;br&gt;
Now, on the test server I have the following .htaccess file in the &lt;code&gt;/stupidteststructure/thesite_test&lt;/code&gt; directory...&lt;br&gt;
&lt;pre&gt;&lt;br&gt;
RewriteRule ^$                        /stupidteststructure/thesite_test/content/  [R]&lt;br&gt;
RewriteRule ^content$                 /stupidteststructure/thesite_test/content/  [R]&lt;br&gt;
RewriteRule ^content/$                /stupidteststructure/thesite_test/process.php?page_alias=index  [L,QSA]&lt;br&gt;
RewriteRule ^content/(.*?)([/]*)$     /stupidteststructure/thesite_test/process.php?page_alias=$1  [L,QSA]&lt;br&gt;
&lt;/pre&gt;&lt;br&gt;
&lt;br&gt;
It could probably be improved, but it works and everyone is happy.&lt;br&gt;
&lt;br&gt;
Now, the problem is, when the code is copied to the live server, including the htaccess file, it all breaks because /stupidteststructure/thesite_test doesn&apos;t exist on that machine.&lt;br&gt;
&lt;br&gt;
Is there a good simple way to make this more generic, or am I going to have to add conditional rewrites for the two servers?&lt;br&gt;
&lt;br&gt;
I&apos;m hoping there is something simple like the following, where RTTD is some super sekrit &quot;Relative to this directory&quot; flag...&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;&lt;br&gt;
RewriteRule ^$                        content/  [RTTD,R]&lt;br&gt;
RewriteRule ^content$                 content/  [RTTD,R]&lt;br&gt;
RewriteRule ^content/$                process.php?page_alias=index  [RTTD,L,QSA]&lt;br&gt;
RewriteRule ^content/(.*?)([/]*)$     process.php?page_alias=$1  [RTTD,L,QSA]&lt;br&gt;
&lt;/pre&gt;&lt;br&gt;
&lt;br&gt;
Help? I&apos;m supposed to have gone home half an hour ago... :)</description>
		<guid isPermaLink="false">post:ask.metafilter.com,2009:site.126868</guid>
		<pubDate>Wed, 08 Jul 2009 09:33:28 -0800</pubDate>
		<dc:creator>twine42</dc:creator>
		
			<category>modrewrite</category>
		
			<category>mod_rewrite</category>
		
			<category>htaccess</category>
		
			<category>Ihatemodrewrite</category>
		
	</item> <item>
		<title>By: devbrain</title>
		<link>http://ask.metafilter.com/126868/Can-you-help-me-with-a-modrewrite-problem#1812736</link>	
		<description>You can do a RewriteRule to populate a variable based on another test -- so, based on the server&apos;s hostname you could fill in a var for either the /stupidserverstructure/ string for dev, or blank for prod.&lt;br&gt;
&lt;br&gt;
Look at the E= flag.  If this isn&apos;t enough, and no-one else points you the answer, I&apos;ll have a poke at it later and try to generate a full receipe.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2009:site.126868-1812736</guid>
		<pubDate>Wed, 08 Jul 2009 09:38:58 -0800</pubDate>
		<dc:creator>devbrain</dc:creator>
	</item><item>
		<title>By: devbrain</title>
		<link>http://ask.metafilter.com/126868/Can-you-help-me-with-a-modrewrite-problem#1812775</link>	
		<description>Ok, here&apos;s a recipe that does it.  I would be hesitant to put this into production, but it demonstrates how it might be done.  (I would rather adapt my file promotion methods than have dev config get pushed into the production server).&lt;br&gt;
&lt;br&gt;
&lt;code&gt;&lt;br&gt;
RewriteEngine On&lt;br&gt;
&lt;br&gt;
RewriteCond %{HTTP_HOST} ^test.example.com$&lt;br&gt;
RewriteRule ^(.*) -   [E=qPRE:stupidteststructure/thesite_test/]&lt;br&gt;
&lt;br&gt;
# Replace these with your real rules ....&lt;br&gt;
RewriteRule ^$ /%{ENV:qPRE}foo [R]&lt;br&gt;
&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
YMMV</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2009:site.126868-1812775</guid>
		<pubDate>Wed, 08 Jul 2009 10:04:09 -0800</pubDate>
		<dc:creator>devbrain</dc:creator>
	</item><item>
		<title>By: boaz</title>
		<link>http://ask.metafilter.com/126868/Can-you-help-me-with-a-modrewrite-problem#1812820</link>	
		<description>This sounds like what RewriteBase was designed for.   As long as the path component of the URL in question is the same for both servers, then you can just set that with RewriteBase and then use relative paths just as you theorized above.  So, if the main site is at http://www.example.com/thesite/ and the test site is at http://test.example.com/thesite/, then you can just put &quot;&lt;code&gt;RewriteBase /thesite/&lt;/code&gt;&quot; before the various relatively-defined rules.  If they&apos;re both at the top level URL of their respective domains, then you&apos;ll want just &quot;&lt;code&gt;RewriteBase /&lt;/code&gt;&quot;.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2009:site.126868-1812820</guid>
		<pubDate>Wed, 08 Jul 2009 10:34:11 -0800</pubDate>
		<dc:creator>boaz</dc:creator>
	</item><item>
		<title>By: twine42</title>
		<link>http://ask.metafilter.com/126868/Can-you-help-me-with-a-modrewrite-problem#1812913</link>	
		<description>devbrain - if that works as it appears, that&apos;s exactly what I&apos;m after. Thank you!&lt;br&gt;
&lt;br&gt;
I tried looking through the documentation for the E flag, and it was as superbly vague as I was expecting. Without your follow up, I&apos;m not sure I&apos;d have ever worked that one out.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2009:site.126868-1812913</guid>
		<pubDate>Wed, 08 Jul 2009 11:40:34 -0800</pubDate>
		<dc:creator>twine42</dc:creator>
	</item><item>
		<title>By: twine42</title>
		<link>http://ask.metafilter.com/126868/Can-you-help-me-with-a-modrewrite-problem#1812941</link>	
		<description>&lt;small&gt;w00t!&lt;/small&gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2009:site.126868-1812941</guid>
		<pubDate>Wed, 08 Jul 2009 11:57:50 -0800</pubDate>
		<dc:creator>twine42</dc:creator>
	</item><item>
		<title>By: devbrain</title>
		<link>http://ask.metafilter.com/126868/Can-you-help-me-with-a-modrewrite-problem#1813598</link>	
		<description>You&apos;re welcome ..... but don&apos;t forget the YMMV.  Moving your rewrite config into httpd.conf (or a file included from there) might be a better option for you.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2009:site.126868-1813598</guid>
		<pubDate>Wed, 08 Jul 2009 21:02:29 -0800</pubDate>
		<dc:creator>devbrain</dc:creator>
	</item>
	</channel>
</rss>
