2 Subdomains on one host

Using a single web hosting account to host multiple sites

2 Subdomains on one host

Postby bluevoice » Tue Sep 25, 2007 10:48 am

Hi could you please help me with the following:

I have a main domain like:

www.maindomain.com

On the hoster I have two folders in root:

/public_html/www/site1 and
/public_html/www/site2

What I'd like to accomplish is that if someone goes to www.site1.com it is redirected to the right place (www.maindomain.com/site1) but that he sees www.site1.com in the address bar. I'd like to accomplish the same for www.site2.com

Now I use the following .htaccess code:

Code: Select all
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?site1\.com [NC]
RewriteRule (.*) http://www.maindomain.com/site1/$1 [R=301,L]


and that redirects the proper way i.e.:

www.site1.com --> http://www.maindomain.com/site1

but I'd like it to still show www.site1.com instead of http://www.maindomain.com/site1

Any help would be very appreciated. Thanks.
Last edited by bluevoice on Tue Sep 25, 2007 12:45 pm, edited 1 time in total.
bluevoice
 
Posts: 3
Joined: Tue Sep 25, 2007 10:33 am

Postby richardk » Tue Sep 25, 2007 12:33 pm

If you include http:// in a RewriteRule it will redirect.
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Fix missing trailing slashes for site1.com.
RewriteCond %{HTTP_HOST} ^(www\.)?site1\.com$ [NC]
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

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

Postby bluevoice » Tue Sep 25, 2007 12:41 pm

Thanks Richardk:

I already got it working using this code:

Code: Select all
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?isite1\.com$ [NC]
RewriteRule ^(.*)$ /site1/$1 [QSA,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?site2\.com$ [NC]
RewriteRule ^(.*)$ /site2/$1 [QSA,L]


Is this part of the code you suggested necessary and what does it really do?

Code: Select all
# Fix missing trailing slashes for site1.com.
RewriteCond %{HTTP_HOST} ^(www\.)?site1\.com$ [NC]
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]
bluevoice
 
Posts: 3
Joined: Tue Sep 25, 2007 10:33 am

Postby richardk » Tue Sep 25, 2007 1:01 pm

Ah, i missed out the REDIRECT_STATUS line.

Is this part of the code you suggested necessary and what does it really do?

Yes. If you go to site1.com/a-directory-that-exists (no trailing slash) mod_dir will redirect it to site1.com/site1/a-directory-that-exists/.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby bluevoice » Tue Sep 25, 2007 1:07 pm

Thanks for the explaination, works like a charm. :D
bluevoice
 
Posts: 3
Joined: Tue Sep 25, 2007 10:33 am

Postby richardk » Wed Sep 26, 2007 2:00 pm

So it only redirects for directories, you can/should add
Code: Select all
RewriteCond %{DOCUMENT_ROOT}/site1%{REQUEST_URI}/ -d

before
Code: Select all
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Johnny Come Lately

Postby cdevious » Wed Sep 26, 2007 2:39 pm

Hello! I have a similar situation to Blue Voice, but the code in my htacces file looks a little different. I am also looking for:

www.site1.com instead of http://www.maindomain.com/site1

I am brand new to this and wondered how to modify my htaccess file to achieve this goal. It currently looks like this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^site1.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.site1.com$
RewriteRule ^(.*)$ http://www.maindomain.com/site1 [R=301,L]


Any help is greatly appreciated.

Thanks a Million!

CD[/code]
cdevious
 
Posts: 2
Joined: Wed Sep 26, 2007 2:32 pm

Postby richardk » Wed Sep 26, 2007 2:50 pm

All the mod_rewrite you need is already in this thread.

Code: Select all
Options +FollowSymLinks

RewriteEngine On

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

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

Postby cdevious » Wed Sep 26, 2007 4:25 pm

thanks rickardk and bluevoice. it is working for me now.
cdevious
 
Posts: 2
Joined: Wed Sep 26, 2007 2:32 pm


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 32 guests

cron