Subdomain to different folder

Using a single web hosting account to host multiple sites

Subdomain to different folder

Postby areidmtm » Thu Aug 24, 2006 10:50 am

Hello!

I have tried searching, but I haven’t sound what I am looking for. Maybe I don’t know what I am looking for.

What I want to do is, make this URL name.domain.com to be silently redirect to http://www.domain.com/name while keeping the URL name.domain.com

My host places ALL sub domain for all the main domains in the /public_html/ folder. The domain that I want to redirect is an add-on domain. So when I add an add-on domain it creates a new folder in the /public_html/ folder. And then when I add a sub domain to that add-on domain, it creates a folder in /public_html/ and not in the add-on domain.

So instead of name.domain.com pulling from /public_html/name I want it to pull from /public_html/add-on/name

Does any of that may sense?

Thanks for you help!

-Alex
areidmtm
 
Posts: 20
Joined: Thu Aug 24, 2006 10:43 am

Postby richardk » Thu Aug 24, 2006 11:18 am

Try this, in your main /public_html dircetory:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^([^\.]+)\.ADD-ON-DOMAIN$ [NC]
RewriteRule !^ADD-ON-DIR(/.*)?$ /ADD-ON-DIR/%1/$1 [QSA,L]


Replace ADD-ON-DOMAIN with the addon domain (no www). Escape any "."s with a "\", eg "google.com" becomes "google\.com".
Replace both ADD-ON-DIRs with the dircetory of your addon domain.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby areidmtm » Thu Aug 24, 2006 11:31 am

Excellent! Thanks, it works. However, sometimes I will get an Internal Server Error. But if I refresh, then it works, but if I refresh again, I will get that error again.

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^([^\.]+)\.addon-domain\.net$ [NC]
RewriteRule !^/addon-domain/(/.*)?$ /addon-domain/%1/$1 [QSA,L]
areidmtm
 
Posts: 20
Joined: Thu Aug 24, 2006 10:43 am

Postby areidmtm » Thu Aug 24, 2006 11:48 am

Actually, apparently it is just loading a blank page
areidmtm
 
Posts: 20
Joined: Thu Aug 24, 2006 10:43 am

Postby richardk » Thu Aug 24, 2006 12:00 pm

You have two extra /s, replace this:
Code: Select all
!^/addon-domain/(/.*)?$

with this:
Code: Select all
!^addon-domain(/.*)?$
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby areidmtm » Thu Aug 24, 2006 12:04 pm

yeah, that's not working either....hummm. Maybe I'll just use a normal redirect to the URL

Thanks for you help!
areidmtm
 
Posts: 20
Joined: Thu Aug 24, 2006 10:43 am

Postby richardk » Thu Aug 24, 2006 1:28 pm

Oops, i made a big mistake:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST}  !^(www\.)?addon-domain\.net$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.addon-domain\.net$ [NC]
RewriteRule !^addon-domain(/.*)?$ /addon-domain/%1%{REQUEST_URI} [QSA,L]


And if that still doesn't work:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST}  !^(www\.)?addon-domain\.net$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.addon-domain\.net$ [NC]
RewriteRule ^(.*)$ http://addon-domain.net/%1/$1 [P,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby areidmtm » Thu Aug 24, 2006 6:24 pm

neither work. The first one I get a 500 error and the other is a 404 '/' not found
areidmtm
 
Posts: 20
Joined: Thu Aug 24, 2006 10:43 am

Postby roxer82 » Thu Sep 07, 2006 8:38 am

Hi, I need to do something like this but I need to say to what specific folder should it go.
For example this subdomains:
- test.domain.com
- test2.domain.com
- test3.domain.com
should go to the folder /public_html/test/
and:
- something.domain.com
- newtest.domain.com
- onemore.domain.com
should go to /public_html/something/

At the moment they are going to each subdomain folder.
I wait for your answer, thanks in advanced!
roxer82
 
Posts: 8
Joined: Thu Sep 07, 2006 8:25 am

Postby richardk » Thu Sep 07, 2006 9:07 am

Try this first:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(test|test2|test3)\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/test/$1 [P,L]

RewriteCond %{HTTP_HOST} ^(something|newtest|onemore)\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/somehting/$1 [P,L]


If that doesn't work, you will need to change it so all those subdomains point to your main doucment root (but if you can do that, you could set them to your chosen directory). Mod_rewrite can't go below the subdomains docuement root (eg. public_html/ and then to the subdirectory). If you change it so all those subdomains point to your main doucment root you can use this:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(test|test2|test3)\.domain\.com$ [NC]
RewriteRule !^test(/.*)?$ /test%{REQUEST_URI}[QSA,L]

RewriteCond %{HTTP_HOST} ^(something|newtest|onemore)\.domain\.com$ [NC]
RewriteRule !^somehting(/.*)?$ /somehting%{REQUEST_URI}[QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Next

Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 26 guests

cron