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 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.)
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.)
Response by poster: 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, 2008
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, 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
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 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, 2008
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
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} 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, 2008
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, 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
posted by holgate at 8:25 AM on June 3, 2008
This thread is closed to new comments.
Redirect / http://sub1.mysite.com/
More on mod_alias.
posted by Remy at 4:14 AM on June 2, 2008