getting .htaccess to do httpd.conf's job
June 2, 2008 3:37 AM   Subscribe

Mod_rewrite and subdirectories and subdomains, oh my!

I'm using a hosting service (Lunarpages) that maps the document root of subdomains to a corresponding subdirectory in the primary domain root (i.e. the public_html directory). Thus: sub1.mysite com has as its / directory.

I've also got, which has its document root automatically and unalterably set to I would like URLs to to be rewritten so that they go to A standard external redirect isn't going to work in this case, because the code in /foo/ needs to parse the incoming subdomain.

Got .htaccess, anyone?

(This is, of course, something that would take 0.3s to solve if I could get at the bloody httpd.conf.)
posted by holgate to Computers & Internet (8 answers total) 1 user marked this as a favorite
Place .htaccess in ~/public_html/sub2/ with this line:

Redirect /

More on mod_alias.
posted by Remy at 4:14 AM on June 2, 2008

Response by poster: Thanks, but that's a straight redirect.

Let me clarify: I need the URL to read, but the content to be drawn from the hierarchy.
posted by holgate at 5:05 AM on June 2, 2008

Unless I misunderstand the problem (which may be likely), a symlink behind the scenes might do what you seek.
posted by devbrain at 5:38 AM on June 2, 2008

i don't use lunarpages so I don't know who you ask to have this done but you'll want someone to alter the dns zonefile so that the sub1 subdomain access the subdirectory (that way appears the same in your browser's address bar).

if you tell them what's what you want, they should be able to help you out
posted by wangarific at 5:47 AM on June 2, 2008

If you don't want a client-side redirect, why not:

Alias / /home/holgate/public_html/sub1/
posted by enn at 6:28 AM on June 2, 2008

Best answer: You want the proxy flag in mod_rewrite (but note that mod_proxy also needs to be installed). Something like this:

RewriteCond %{HTTP_HOST}
RewriteRule /(.*)$1 [P]

Proxying will pass the request through to sub1 but you'll have access to the original hostname for processing.

Note that users will see in their browser, always. If you need them to see sub1 then you'll have to use RewriteRule to set a flag along with external redirection, which is inconvenient and fragile.
posted by nev at 8:03 AM on June 2, 2008

Response by poster: Proxy flag is it, but they want to upsell to enable mod_proxy. Gah. Thanks, anyway.
posted by holgate at 8:25 AM on June 3, 2008

Sorry, that's totally lame.
posted by nev at 6:25 AM on June 4, 2008

« Older Which tense in a wedding gift message?   |   dude, what's my dog? Newer »
This thread is closed to new comments.