Dmain Name redirect to sub-folder

Using a single web hosting account to host multiple sites

Dmain Name redirect to sub-folder

Postby 78tahitman » Tue Oct 23, 2007 5:48 pm

Ok, I have been searching this site for about two hours now and I cannot find a straight answer to the problem that I am having. I have tried a few codes, but none of them seem to work.

Basically, here is my problem in a nut-shell:

I have one hosting account:
www.mainsite.com

I have three other domains that point to subfolders under the main account. For example:

www.secondsite.com is supposed to point to www.mainsite.com/secondsite/index.htm

I also have www.thirdsite.com which is supposed to point to www.mainsite.com/thirdstie/index.htm

and www.fourthsite.com to go to www.mainsite.com/fourthsite/index.htm

What code do I need to use to get this to work. I have tried the test code of:

Options +FollowSymLinks

RewriteEngine On

RewriteRule Google http://www.google.com/? [NC,R,L]

to make sure it is working and when I went to www.mainsite.com/google I was redirected to www.google.com. So I beleive my .htacess file is working.

I guess I should also have started with, I am a complete noob and have no idea what I am doing with htacess files, so please be gentle with me. I need to get these other three sub-sites (domain names) working, but I can't seem to enter the right code. Can anyone help?

Now, this is only the first step in this htacess file mod_rewrite that I want to do. The old way it worked was that when you typed in www.secondsite.com, it would show in the address bars as www.mainsite.com/secondsite/index.htm. Which is fine for now. I have read other codes to be able to change that. I have also read about changing the www.mainsite.com/folder to show up as www.folder.mainsite.com and I think I can do that, but my first problem is just getting the domain names to work.
78tahitman
 
Posts: 4
Joined: Tue Oct 23, 2007 5:40 pm
Location: Ohio

Postby richardk » Wed Oct 24, 2007 12:51 pm

So the domains all go to the same place at the moment? Are they always .com?

Try the following in a .htaccess file in your document root
Code: Select all
Options +FollowSymLinks

RewriteEngine On

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

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

Postby richardk » Fri Oct 26, 2007 3:07 pm

Sorry for the delay in getting back to you. Basically, here is what I need for a .htacess code:

I have one hosting account:
www.domain.com

I have three other domains that point to subfolders under the main account. For example:

www.domain2.com is supposed to point to www.domain.com/domain2/index.htm

I also have www.domain3.com which is supposed to point to www.domain.com/dom3/index.htm

and www.domain4.com to go to www.domain.com/dom4/index.htm

What code do I need to use to get this to work?

Right now, www.domain2.com, www.domain3.com, and www.domain4.com points directly to www.domain.com.

Thank you very much for your time.


Try the following in a.htaccess file in your document root
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Fix missing trailing slashes.
RewriteCond /domain2%{HTTP_HOST} ^(/domain2)(www\.)?domain2\.com$ [NC,OR]
RewriteCond /dom3%{HTTP_HOST}    ^(/dom3)(www\.)?domain3\.com$    [NC,OR]
RewriteCond /dom4%{HTTP_HOST}    ^(/dom4)(www\.)?domain4\.com$    [NC]
RewriteCond %{DOCUMENT_ROOT}%1%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

# Rewrite:
#  domain2.com/* --> /domain2/*
#  domain3.com/* --> /dom3/*
#  domain4.com/* --> /dom4/*
RewriteCond /domain2%{HTTP_HOST} ^(/domain2)(www\.)?domain2\.com$ [NC,OR]
RewriteCond /dom3%{HTTP_HOST}    ^(/dom3)(www\.)?domain3\.com$    [NC,OR]
RewriteCond /dom4%{HTTP_HOST}    ^(/dom4)(www\.)?domain4\.com$    [NC]
RewriteRule .* %1%{REQUEST_URI} [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby 78tahitman » Fri Oct 26, 2007 3:56 pm

Works like a charm..... You don't know how much I appreciate it.

Now for the next issue....

When I go to www.domain2.com it shows up in the address bar as http:///domain1.com/dom2 (with no www.)

What is the code to have it still show up as www.domain2.com in the address bar
78tahitman
 
Posts: 4
Joined: Tue Oct 23, 2007 5:40 pm
Location: Ohio

Postby richardk » Fri Oct 26, 2007 4:48 pm

Oops, my mistake, replace the last [R=301,L] with [QSA,L] and clear your browser's cache.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby 78tahitman » Fri Oct 26, 2007 6:15 pm

When I did that, I get this:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@domain1.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.


Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
78tahitman
 
Posts: 4
Joined: Tue Oct 23, 2007 5:40 pm
Location: Ohio

Postby richardk » Sat Oct 27, 2007 4:33 pm

Add
Code: Select all
RewriteCond %{ENV:REDIRECT_STATUS} ^$

after
Code: Select all
#  domain4.com/* --> /dom4/*
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby 78tahitman » Mon Feb 11, 2008 4:36 pm

Ok, my next question is that to get to my forum and gallery and store on my website, you have to go to www.mydomain.com/forum/index.php, or www.mydomain.com/store/index.php, and so on. Can I mod the HTACCESS file so that I can tell people to go to http://forum.mydomain.com, or http:store.mydomain.com and get them to those same pages. Just for something that is easier to put in emails and such to direct people to thos eareas of my website.
78tahitman
 
Posts: 4
Joined: Tue Oct 23, 2007 5:40 pm
Location: Ohio

Postby richardk » Mon Feb 11, 2008 4:47 pm

Create the sub domains in your hosting control panel. If they don't automatically go to those sub directories, try adding
Code: Select all
RewriteCond /forum%{HTTP_HOST} ^(/forum)(www\.)?forum\.example\.com$ [NC,OR]
RewriteCond /store%{HTTP_HOST} ^(/store)(www\.)?store\.example\.com$ [NC,OR]

to each rule.
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 2 guests

cron