domains and subdomains to folder

Using a single web hosting account to host multiple sites

domains and subdomains to folder

Postby jaaa » Sat Jan 05, 2008 4:31 am

Hi,

i searched all the forum, but i didn't find how to do it, only for static domains.

I need to rewrite these:

anydomain.anytld to /some/directory/anydomain.anytld/www
www.anydomain.anytld to /some/directory/anydomain.anytld/www
anysubdomain.anydomain.anytld to /some/directory/anydomain.anytld/anysubdomain

Thanks for any help!
jaaa
 
Posts: 6
Joined: Sat Jan 05, 2008 4:25 am

Postby richardk » Sat Jan 05, 2008 10:21 am

Do you have access to the httpd.conf file? If you do, do not use mod_rewrite, use mod_vhost_alias.

anydomain.anytld to /some/directory/anydomain.anytld/www
www.anydomain.anytld to /some/directory/anydomain.anytld/www
anysubdomain.anydomain.anytld to /some/directory/anydomain.anytld/anysubdomain

What about two part second-level domains like co.uk?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby jaaa » Sun Jan 06, 2008 2:59 am

Yes, I have the access to httpd.conf.

I tried to do it with help of mod_vhost_alias, but I wasn't sucessfull. I had a problem with anydomain.anytld pointing to /somewhere/anydomain.anytld/www.

Do not worry about co.uk domain, it will be treated as anydomain.anytld/anysubdomain.

Thanks.
jaaa
 
Posts: 6
Joined: Sat Jan 05, 2008 4:25 am

Postby richardk » Sun Jan 06, 2008 1:07 pm

Try
Code: Select all
<VirtualHost *:80>
  ServerName          1
  ServerAlias         www.*
  VirtualDocumentRoot /path/to/%2+
</VirtualHost>

<VirtualHost *:80>
  ServerName          2
  VirtualDocumentRoot /path/to/%2+/%1
</VirtualHost>

It should actually work for SLDs.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby jaaa » Tue Jan 15, 2008 3:47 am

It doesn't work for subdomains, everything ends at /path/to/%2

http request was for aaa.xxx.yy

[Tue Jan 15 12:42:16 2008] [error] [client 62.209.xxx.yyy] Directory index forbidden by Options directive: /mnt/pelisek/web/xxx.yy/
jaaa
 
Posts: 6
Joined: Sat Jan 05, 2008 4:25 am

Postby richardk » Tue Jan 15, 2008 12:37 pm

Are you using Apache 1.3?

Try
Code: Select all
<VirtualHost *:80>
  ServerName          1
  DocumentRoot /nowhere
  Options +FollowSymLinks

  RewriteEngine On

  # Add missing trailing slashes.
  RewriteCond %{HTTP_HOST} ^(www\.)?()([^\.]+\.[^\.]+)$ [NC,OR]
  RewriteCond %{HTTP_HOST}/ ^(www\.)?([^\.]+)\.([^\.]+\.[^\.]+)(/)$ [NC]
  RewriteCond /path/to/%3%4%2%{REQUEST_URI}/ -d
  RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

  # Document roots.
  RewriteCond %{HTTP_HOST} ^(www\.)?()([^\.]+\.[^\.]+)$ [NC,OR]
  RewriteCond %{HTTP_HOST}/ ^(www\.)?([^\.]+)\.([^\.]+\.[^\.]+)(/)$ [NC]
  RewriteRule ^(/.*)$ /%3%4%2$1 [QSA,PT,L]
</VirtualHost>
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby jaaa » Wed Jan 16, 2008 2:12 am

I have

Server version: Apache/2.2.4 (Ubuntu)
Server built: Oct 4 2007 22:47:20

maybe there is some bug in mod_vhost_alias
jaaa
 
Posts: 6
Joined: Sat Jan 05, 2008 4:25 am

Postby richardk » Wed Jan 16, 2008 4:24 pm

maybe there is some bug in mod_vhost_alias

I doubt it, it's just not right. Try
Code: Select all
<VirtualHost *:80>
  ServerName          1
  VirtualDocumentRoot /path/to/%2+/%1

<VirtualHost *:80>
  ServerName          2
  ServerAlias         www.*
  VirtualDocumentRoot /path/to/%2+
</VirtualHost>
</VirtualHost>

The first one must be the first of all your <VirtualHost>s.

Did the mod_rewrite work?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby jaaa » Mon Jan 21, 2008 5:14 am

yes, this is working, but

<VirtualHost *:80>
ServerName 1
VirtualDocumentRoot /path/to/%2+/%1
</VirtualHost>

<VirtualHost *:80>
ServerName 2
ServerAlias www.*
VirtualDocumentRoot /path/to/%2+/www
</VirtualHost>

instead of

<VirtualHost *:80>
ServerName 1
VirtualDocumentRoot /path/to/%2+/%1

<VirtualHost *:80>
ServerName 2
ServerAlias www.*
VirtualDocumentRoot /path/to/%2+
</VirtualHost>
</VirtualHost>

I will try that one with rewrite.

Thanks a lot :)
jaaa
 
Posts: 6
Joined: Sat Jan 05, 2008 4:25 am

Postby jaaa » Mon Jan 21, 2008 6:04 am

One note:

it's working fine with *.domain.tld, but when domain.tld is accessed it doesn't work.

For example accessing sportmag.cz

[Mon Jan 21 15:03:15 2008] [error] [client xxx.xxx.xxx.xxx] File does not exist: /mnt/pelisek/web/cz

correct path should be /mnt/pelisek/web/sportmag.cz/www
jaaa
 
Posts: 6
Joined: Sat Jan 05, 2008 4:25 am

Next

Return to Domain Handling

Who is online

Users browsing this forum: Majestic-12 [Bot] and 18 guests

cron