(sub) domains handling

Using a single web hosting account to host multiple sites

(sub) domains handling

Postby ermac0 » Fri Jul 20, 2007 8:41 am

Hi!

Recently I moved my websites to new hosting provider (share hosting). I have few domains and I'm using subdomains as well. Because websites use some common components I tend to have one copy of those libraries and sym-link them into every website's folder. So that whenever I update them all websites use fresh version.

Anyway on my previous hosting account I could point every domain or subdomain to its own folder and I had ability to link folders which were above (in hierarchy) website's folder. On new account I'm not able to do that. So the only way to maintain my system is to point all domains to account's root dir and use mod_rewrite from there. I have manage to do so, but some requests fail. This is my folders structure and then mod_rew file

Code: Select all
root
    website1
        mainpage
        sub1
    website2
        mainpage
        sub1
        sub2
        ....
    website3
    ....


Here's a piece of my .htaccess file, located in root folder:
Code: Select all
RewriteEngine On

#### domain1.com
RewriteCond %{HTTP_HOST} ^(www\.|)domain1\.com$ [NC]
RewriteRule ^ /website1/mainpage%{REQUEST_URI} [L]

#### sub1.domain1.com
RewriteCond %{HTTP_HOST} ^(www\.|)sub1\.domain1\.com$ [NC]
RewriteRule ^ /website1/sub1%{REQUEST_URI} [L]

#### domain2.com
RewriteCond %{HTTP_HOST} ^(www\.|)domain2\.com$ [NC]
RewriteRule ^ /website2/mainpage%{REQUEST_URI} [L]
......


I have a lot redirects which look like '/dir/file.php' within my websites, which now seem to fail.
Maybe I missed something. Any one knows better domains handling?

I tried also this:
RewriteCond %{HTTP_HOST} ^(www\.|)domain1\.com$ [NC]
RewriteRule ^(.*)$ /website1/mainpage/$1 [L]

which resulted Error 500

Thanks in advance
ermac0
 
Posts: 1
Joined: Fri Jul 20, 2007 8:15 am

Postby richardk » Fri Jul 20, 2007 12:07 pm

I have a lot redirects which look like '/dir/file.php' within my websites, which now seem to fail.

What kind of redirect? In a .htaccess file? In your script? What happens? (Can you get the response headers?)

Any one knows better domains handling?

If you name the directory the same as the domain name (eg. domain-one.com to /domain-one/ and suba.domain-one.com to /domain-one/suba/) you could have a rule set that worked for all domains and another for all sub domains.

If not, i'd do it like this
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Don't loop.
RewriteCond %{ENV:REDIRECT_STATUS} !^$
RewriteRule .* - [L]

# domain1.com
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com$ [NC]
RewriteRule ^(.*)$ /website1/mainpage/$1 [QSA,L]

#...
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 9 guests

cron