<?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: Redirecting subdomains with mod_rewrite</title>
      <link>http://ask.metafilter.com/22852/Redirecting-subdomains-with-modrewrite/</link>
      <description>Comments on Ask MetaFilter post Redirecting subdomains with mod_rewrite</description>
	  	  <pubDate>Fri, 19 Aug 2005 16:37:21 -0800</pubDate>
      <lastBuildDate>Fri, 19 Aug 2005 16:37:21 -0800</lastBuildDate>
      <language>en-us</language>
	  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
	  <ttl>60</ttl>

<item>
  	<title>Question: Redirecting subdomains with mod_rewrite</title>
  	<link>http://ask.metafilter.com/22852/Redirecting-subdomains-with-modrewrite</link>	
  	<description>A subdomain redirection question (any mod_rewrite experts?) &lt;br /&gt;&lt;br /&gt; So let&apos;s say that I&apos;m setting up my new site, sports.com.  Here is what I&apos;d like to do:&lt;br&gt;
&lt;br&gt;
When someone visits http://baseball.sports.com, I would like them to be redirected to http://sports.com/index.php?id=baseball (but transparently, so http://baseball.sports.com still appears in their browser).  I would like to do this with several subdomains, but I don&apos;t need to handle *.sports.com (my webhost doesn&apos;t support wildcarded DNS entries anyway).&lt;br&gt;
&lt;br&gt;
I realize I could fake this with frames, but that seems kind of lame.  After wading through tons of .htaccess &amp;amp; mod_rewrite info, I&apos;m more confused than ever.  Can anyone help me pull this off?</description>
  	<guid isPermaLink="false">post:ask.metafilter.com,2008:site.22852</guid>
  	<pubDate>Fri, 19 Aug 2005 16:01:58 -0800</pubDate>
  	<dc:creator>subclub</dc:creator>
	
	<category>mod_rewrite</category>
	
	<category>htaccess</category>
	
	<category>subdomain</category>
	
	<category>redirection</category>
	
	<category>internet</category>
	
	<category>web</category>
	
</item>
<item>
  	<title>By: nicwolff</title>
  	<link>http://ask.metafilter.com/22852/Redirecting-subdomains-with-modrewrite#365434</link>	
  	<description>No time to test it, but point all the domains at one server and something like&lt;br&gt;
&lt;br&gt;
RewriteCond %{HTTP_HOST} ([^.]+)\.sports.com [NC]&lt;br&gt;
RewriteRule /index.php?id=%1&lt;br&gt;
&lt;br&gt;
should work.</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.22852-365434</guid>
  	<pubDate>Fri, 19 Aug 2005 16:37:21 -0800</pubDate>
  	<dc:creator>nicwolff</dc:creator>
</item>
<item>
  	<title>By: odinsdream</title>
  	<link>http://ask.metafilter.com/22852/Redirecting-subdomains-with-modrewrite#365438</link>	
  	<description>Oooho!! Could I pretty-please tack on a similar question?&lt;br&gt;
&lt;br&gt;
How do I redirect into a subdirectory without the .htaccess rules filtering down into said subdirectory from the parent file?&lt;br&gt;
&lt;br&gt;
As in, visiting www.domain.com should automatically forward to www.domain.com/photos&lt;br&gt;
&lt;br&gt;
So, in ~/public_html/.htaccess:&lt;br&gt;
Redirect / http://www.domain.com/photos&lt;br&gt;
&lt;br&gt;
Great! That works, but then when the browser arrives at ~/public_html/photos/, it looks for any parent .htaccess rules, finds one in the directory above, and does the redirect a &lt;em&gt;second&lt;/em&gt; time, so then the browser goes forward again to www.domain.com/photos/photos, then fails.&lt;br&gt;
&lt;br&gt;
What gives?</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.22852-365438</guid>
  	<pubDate>Fri, 19 Aug 2005 16:43:47 -0800</pubDate>
  	<dc:creator>odinsdream</dc:creator>
</item>
<item>
  	<title>By: subclub</title>
  	<link>http://ask.metafilter.com/22852/Redirecting-subdomains-with-modrewrite#365452</link>	
  	<description>nicwolff:&lt;br&gt;
&lt;br&gt;
using that code a get a 500 error.  i think the first line should be: &lt;br&gt;
RewriteCond %{HTTP_HOST} ([^.]+)/.sports.com [NC]&lt;br&gt;
&lt;br&gt;
when i do that, there are no errors, but it doesn&apos;t actually do any redirecting (just dispalys whatever is actually at baseball.sports.com).</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.22852-365452</guid>
  	<pubDate>Fri, 19 Aug 2005 17:08:45 -0800</pubDate>
  	<dc:creator>subclub</dc:creator>
</item>
<item>
  	<title>By: subclub</title>
  	<link>http://ask.metafilter.com/22852/Redirecting-subdomains-with-modrewrite#365456</link>	
  	<description>wow, my typing is horrible.</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.22852-365456</guid>
  	<pubDate>Fri, 19 Aug 2005 17:15:05 -0800</pubDate>
  	<dc:creator>subclub</dc:creator>
</item>
<item>
  	<title>By: subclub</title>
  	<link>http://ask.metafilter.com/22852/Redirecting-subdomains-with-modrewrite#365461</link>	
  	<description>i should also note that with this code:&lt;br&gt;
&lt;br&gt;
RewriteCond %{HTTP_HOST} ([^.]+)/.sports.com [NC]&lt;br&gt;
&lt;br&gt;
i still get a 500 error on plain old sports.com</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.22852-365461</guid>
  	<pubDate>Fri, 19 Aug 2005 17:35:21 -0800</pubDate>
  	<dc:creator>subclub</dc:creator>
</item>
<item>
  	<title>By: null terminated</title>
  	<link>http://ask.metafilter.com/22852/Redirecting-subdomains-with-modrewrite#365468</link>	
  	<description>odinsdream:&lt;br&gt;
&lt;br&gt;
RewriteEngine On&lt;br&gt;
RewriteCond %{REQUEST_URI}  !photos [NC]&lt;br&gt;
RewriteRule ^(.*) http://www.domain.com/photos&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Untested.</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.22852-365468</guid>
  	<pubDate>Fri, 19 Aug 2005 17:46:20 -0800</pubDate>
  	<dc:creator>null terminated</dc:creator>
</item>
<item>
  	<title>By: Auz</title>
  	<link>http://ask.metafilter.com/22852/Redirecting-subdomains-with-modrewrite#365480</link>	
  	<description>&amp;quot;using that code a get a 500 error. i think the first line should be:&lt;br&gt;
RewriteCond %{HTTP_HOST} ([^.]+)/.sports.com [NC]&amp;quot; &lt;br&gt;
&lt;br&gt;
No. &apos;\.&apos; means a dot (&apos;\&apos; = &apos;the next character is the real one&apos;) since a dot on it&apos;s own means any character. &apos;/.&apos; means just slash dot - so unless your domain really is &apos;baseball/.sports.com&apos; it wouldn&apos;t match the pattern and not do anything.&lt;br&gt;
&lt;br&gt;
I&apos;m not sure why the original suggestions 500s - I think it&apos;s because [^.]+ would be a test for &amp;quot;not anything more than once&amp;quot;. I would have used&lt;br&gt;
&lt;br&gt;
RewriteCond %{HTTP_HOST} (.+?)\.sports\.com [NC]&lt;br&gt;
&lt;br&gt;
But then I usually never get regexps right on the first go. It mignt need the &apos;start of line&apos; marker at the front.&lt;br&gt;
&lt;br&gt;
RewriteCond %{HTTP_HOST} ^(.+?)\.sports\.com [NC]&lt;br&gt;
&lt;br&gt;
(all are untested. ymmv.)</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.22852-365480</guid>
  	<pubDate>Fri, 19 Aug 2005 17:59:56 -0800</pubDate>
  	<dc:creator>Auz</dc:creator>
</item>
<item>
  	<title>By: boaz</title>
  	<link>http://ask.metafilter.com/22852/Redirecting-subdomains-with-modrewrite#365492</link>	
  	<description>The RewriteRule line is causing the syntax error; it&apos;s missing the replaced pattern and only includes the substitution.&lt;br&gt;
&lt;br&gt;
However, it still doesn&apos;t quite work; the problem is that you want to change hostnames, and an internal rewrite can&apos;t do that.  You need to do an internal proxy request using the [P] flag on the RewriteRule line:&lt;blockquote&gt;&lt;code&gt;RewriteCond %{HTTP_HOST} ([^.]+)\.sports.com [NC]&lt;br&gt;
RewriteRule ^(.*) http://sports.com/index.php?id=%1 [P]&lt;/code&gt;&lt;/blockquote&gt;The rule I gave makes any request to any baseball.sports.com return the same index page, but that&apos;s probably not what you want.  Unfortunately, I&apos;d need to know a bit more about how your web app is structured before I could do better.  For example, given your example just references a generic index page, maybe you just want the subdomain removed from the domain name and added generally as a query.  For that, the 2nd line would be &lt;code&gt;RewriteRule (.*) http://sports.com$1?id=%1 [P]&lt;/code&gt; .  All in all, I&apos;d recommend just doing a browser redirect, since it&apos;s well understood by users, and prevents you from having to think too hard about what the various permutations of subdomain URLs.&lt;br&gt;
&lt;br&gt;
PS.  odinsdream, just use &lt;code&gt;RedirectMatch ^/$ http://www.domain.com/photos&lt;/code&gt; so only the top level URL and no others are redirected.</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.22852-365492</guid>
  	<pubDate>Fri, 19 Aug 2005 18:43:12 -0800</pubDate>
  	<dc:creator>boaz</dc:creator>
</item>
<item>
  	<title>By: boaz</title>
  	<link>http://ask.metafilter.com/22852/Redirecting-subdomains-with-modrewrite#365501</link>	
  	<description>Oh yeah, and I really shouldn&apos;t have just copied nicwolff&apos;s RewriteCond line, since it&apos;s got a few unescaped periods.  Howzabout &lt;code&gt;RewriteCond %{HTTP_HOST} ([^\.]+)\.sports\.com [NC]&lt;/code&gt; instead?</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.22852-365501</guid>
  	<pubDate>Fri, 19 Aug 2005 19:11:21 -0800</pubDate>
  	<dc:creator>boaz</dc:creator>
</item>
<item>
  	<title>By: odinsdream</title>
  	<link>http://ask.metafilter.com/22852/Redirecting-subdomains-with-modrewrite#365569</link>	
  	<description>boaz: Thanks, that works perfectly!</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.22852-365569</guid>
  	<pubDate>Fri, 19 Aug 2005 21:49:42 -0800</pubDate>
  	<dc:creator>odinsdream</dc:creator>
</item>
<item>
  	<title>By: Rhomboid</title>
  	<link>http://ask.metafilter.com/22852/Redirecting-subdomains-with-modrewrite#365642</link>	
  	<description>It should be unnecessary (but harmless) to backslash . inside of braces.  [.] means a character class consisting of a period, not of any character.</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.22852-365642</guid>
  	<pubDate>Sat, 20 Aug 2005 01:51:08 -0800</pubDate>
  	<dc:creator>Rhomboid</dc:creator>
</item>
<item>
  	<title>By: nicwolff</title>
  	<link>http://ask.metafilter.com/22852/Redirecting-subdomains-with-modrewrite#366011</link>	
  	<description>&lt;i&gt;The RewriteRule line is causing the syntax error; it&apos;s missing the replaced pattern and only includes the substitution.&lt;/i&gt;&lt;br&gt;
&lt;br&gt;
Whoops! Thanks for fixing that...</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.22852-366011</guid>
  	<pubDate>Sat, 20 Aug 2005 20:11:36 -0800</pubDate>
  	<dc:creator>nicwolff</dc:creator>
</item>

    </channel>
</rss>
