Forum Moderators: phranque
My directories structure is below:
/var/www/www.example.com/www
/var/www/www.example.com/user1
/var/www/www.example,com/user2
......................
....................
.....................
I need that if an user asks for AAAA.example.com, Apache returns files in /var/www/www.example.com/AAAA/
This in my /etc/apache2/sites-available/www.example.com:
<VirtualHost *>
ServerName www.example.com
ServerAlias www.example.com *.example.com
DocumentRoot /var/www/www.example.com
<Directory /var/www/www.example.com>
RewriteCond %{HTTP_HOST} ^forum\.example\.com
RewriteCond %{REQUEST_URI} !^/forum/?
RewriteRule ^(.*)$ /forum/$1 [L]
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
The problem is every third level domain registered to DNS server (i.e. forum.example.com, user1.example.com) points to /var/www/www.example.com.
That is, if an user asks for
http://forum.example.com
the server returns:
/var/www/www.example.com/index.html
and not
/var/www/www.example.com/forum/index.html
Can somebody helps me?
Thanks in advance.
[edited by: jdMorgan at 11:19 pm (utc) on Feb. 3, 2006]
[edit reason] No URLs, please. See Terms of Service. [/edit]
RewriteRule ^/(.*)$ /forum/$1 [L]
But that does not look like the main problem. You wrote
That is, if an user asks for http://forum.example.com
the server returns: /var/www/www.example.com/index.html
The first thing I noticed is the missing server config:
Port 80
ServerName local.example.com
#
# Your IP address goes on these lines
NameVirtualHost *:80
#
<VirtualHost *:80>
ServerName www.example.com
ServerAlias [b]ex[/b]ample.com *.example.com
DocumentRoot /var/www/www.example.com
Also, your RewriteRule *does not* add "index.html" to the URL. So there is some other code somewhere that is adding "index.html" and that may be where your problem is.
You can turn on rewrite logging and define a rewrite log file to help you find this problem, since you have access to the server config. See RewriteLog and RewriteLogLevel in the mod_rewrite documentation. Warning: Don't forget to turn logging off when you are done testing; It consumes a lot of server resources when logging, especially if you set the loglevel to a high number.
Jim
In other words, I'd avoid using RewriteRule for doing that,
and try the method that gives exact DOCUMENT_ROOT, as much as possible.
<VirtualHost *>
ServerName www.example.it
ServerAlias www.example.it *.example.it
DocumentRoot /var/www/www.example.it
RewriteCond %{HTTP_HOST} ^forum\.example\.it
RewriteCond %{REQUEST_URI}!^/forum/?
RewriteRule ^/(.*)$ /forum/$1 [L]
<Directory /var/www/www.example.it>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I would like to modify this configuration to allow any third level domain (i.e. feedback.example.it, news.example.it,...) and not just forum.example.it domain.
I've tried this:
RewriteCond %{HTTP_HOST} ^(.*)\.example\.it
RewriteCond %{REQUEST_URI}!^/$1/?
RewriteRule ^/(.*)$ /$1/$2 [L]
but it doesn't work.
Can anybody help me?
Thanks in advance.
The simplest solution involves a slight change to your subdomain-directory names:
RewriteCond %{REQUEST_URI} !^/sdd_
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.example\.it
RewriteRule ^/(.*)$ /sdd_%2/$1 [L]
Jim