getting .htaccess to do httpd.conf's job
June 2, 2008 3:37 AM   RSS feed for this thread 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 mysite.com/sub1/ as its / directory.

I've also got sub2.mysite.com, which has its document root automatically and unalterably set to mysite.com/sub2/. I would like URLs to sub2.mysite.com to be rewritten so that they go to sub1.mysite.com. 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 comments total) 1 user marked this as a favorite
Place .htaccess in ~/public_html/sub2/ with this line:

Redirect / http://sub1.mysite.com/

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


Thanks, but that's a straight redirect.

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


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


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 sub1.mysite.com 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


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


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

RewriteCond %{HTTP_HOST} sub2.mysite.com
RewriteRule /(.*) http://sub1.mysite.com/$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 sub2.mysite.com 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


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


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


« Older I'm a bit confused about wheth...   |   help my friends figure out wha... Newer »

You are not logged in, either login or create an account to post comments



Related Questions
Mod_rewrite to replace extensions? August 13, 2008
Redirect images & mp3s to mirror via htaccess June 26, 2008
Redirecting subdomain to https June 11, 2008
Redirecting subdomains with mod_rewrite August 19, 2005
"You'll gonna need a more sophisticated solution." July 21, 2005