Multiple domains on one host, with different document roots

Using a single web hosting account to host multiple sites

Multiple domains on one host, with different document roots

Postby cyq » Fri Jun 05, 2009 6:13 am

I currently have one domain set up with a hosting plan, and recently purchased and parked an additional domain to the same hosting plan. Let's call these main.com and parked1.com.

I want the domains to point to my folders like this:
main.com -> /home/user/public_html/ and
parked1.com -> /home/user/public_html/parked1/.

Now, I have set up something like this in my .htaccess file:
Code: Select all
RewriteCond %{HTTP_HOST} parked1.com
RewriteCond %{REQUEST_URI} !^/parked1
RewriteRule ^(.*)$ parked1/$1 [L]
...which sort of works.

That is, if i type in parked1.com into my browser, the correct index page is displayed. However, if I try accessing parked1.com/fakefolder/, the same index page shows up. In fact, parked1.com/sub/another_sub/whatever/ or any other "fake" address all point to the same page as parked1.com. Which I find strange. And slightly frustrating. :P

But, if I type parked1.com/parked1/realfolder/, the content at /home/user/public_html/parked1/realfolder/ is loaded. See what's happened here? For some reason I need to add the parked1-bit for it to work.

I hope it's clear what my problem is, I'm sorry if this is a bit hard to read. Any advice as to what I can do to fix it?

Thank you very much.
-cyq
cyq
 
Posts: 2
Joined: Fri Jun 05, 2009 2:52 am

Postby richardk » Fri Jun 05, 2009 10:43 am

Does this mod_rewrite test work?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Fix missing trailing slashes.
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/example%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

# Rewrite sub domains.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ /example/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby cyq » Sat Jun 06, 2009 6:05 am

Hooray!

This works great, no errors so far. It took some hefty debugging to make it work, though. I am currently using a Wordpress configuration on my main.com domain, which included the following code:
Code: Select all
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
...which sure enough messed up my configuration on my parked1.com domain.

All I did to fix it was to add the line
Code: Select all
RewriteCond %{HTTP_HOST} ^main\.com$ [NC]
so that it would only include that domain, and presto. Everything worked smoothly.

I currently have removed the www. in either domain, and I applied that trailing slash fix on my main.com domain as well - both work without a hitch.

Thank you so much for your help! I don't think I'd ever find that code myself. ;) Have a good day! :)

-cyq
cyq
 
Posts: 2
Joined: Fri Jun 05, 2009 2:52 am

Postby richardk » Sat Jun 06, 2009 12:00 pm

I applied that trailing slash fix on my main.com domain as well - both work without a hitch.

You don't need to do that, it should already handled by mod_dir. The mod_rewrite is required for the parked domain because otherwise mod_dir would redirect to example.com/example/dir/ not example.com/dir/.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 17 guests

cron