Redirect Second Domain to Subfolder on Primary Domain?

Status
Not open for further replies.

chatmasta

New member
Jan 7, 2007
2,613
68
0
NYC
Hey,

I'm starting programming on a new project soon, but there's this one kink I want to work out before I write any code. For all intents and purposes, I'm starting a free web hosting site. So a user has his website at freehost.com/sitename. But then he buys an upgrade where he can have his own domain, sitename.com. It is possible for me to own the domain.

What is the best way to redirect sitename.com to freehost.com/sitename? That also means that sitename.com/subfolder will redirect to freehost.com/sitename/subfolder.

I've read that mod_rewrite will be involved, but I haven't really found any clear guides addressing this issue specifically. Also, will things get messy if freehost.com/sitename is not an actual directory, but rather a CakePHP URL?

Thanks.
 


I suck with mod_rewrite, but it sounds like your going to have a good number of redirects and google only follows so many of them before it gives up.

You might want virtual hosting. I think that might just be for "catch all" subdomains.

Name-based Virtual Hosts

I'm not a coder, but it might help.
 
It sounds like you don't want to do any actual 301/302 redirects because then the user's browser URL will change and that breaks the 'illusion' that he is hosted on his own site.

You can do what you want with mod_rewrite. It will do internal reroutes that leave the user's browser url intact.

More specifically, you'll want to have the dns entries for their domains pointing at your webserver, and then have mod_rewrite catch all incoming traffic and rewrite as necessary.
 
I ended up figuring it out guys, thanks. I used a modified version of this guide:

http://holisticnetworking.net/cake/2009/05/one-app-many-subdomains-my-solution/

Basically I just replaced subdomains with addon domains. Very simple and thankfully CakePHP does all the 'routing' for me.


You may be able to even forgo the apache virtual host entries for your new domains. Just make your cake app the default host on apache, and all requests will automatically go there.
 
Status
Not open for further replies.