Results 1 to 16 of 16
Thread: Apache Wildcard Docroots
-
08-23-2007, 11:33 PM #1WHT Addict
- Join Date
- Jun 2006
- Posts
- 115
Apache Wildcard Docroots
Been searching google for a while and havn't stumbled upon anything useful.
I'm trying to have it so username.mydomain.com opens their directory inside /home/users/username
This is what I have but it doesn't seem to be working.
<VirtualHost *:80>
UseCanonicalName off
ServerAlias *.mydomain.com
ServerName *.mydomain.com
DocumentRoot /home/users/%1
</VirtualHost>
Thanks in advance...
-
08-24-2007, 02:53 AM #2Web Hosting Master
- Join Date
- Jan 2006
- Location
- Athens, Greece
- Posts
- 1,481
Whilst you have a catch all domain, it should point to main folder and then handle usernames with mod_rewrite.
-
08-24-2007, 06:48 AM #3Web Hosting Master
- Join Date
- Oct 2004
- Location
- Kerala, India
- Posts
- 4,771
Do this to enable wildcard subdomains.
Add in virtualhost entry the following, so that the VH looks as below. ServerAlias domain.com *.domain.com
Code:<VirtualHost 111.111.111.111> ServerAlias domain.com *.domain.com ServerAdmin webmaster@domain.com DocumentRoot /home/username/public_html </VirtualHost>
Add in zone file of the domain
Code:* IN A IP
David | www.cliffsupport.com
Affordable Server Management Solutions sales AT cliffsupport DOT com
CliffWebManager | Access WHM from iPhone and Android
-
08-24-2007, 07:39 AM #4Web Hosting Master
- Join Date
- May 2006
- Location
- India
- Posts
- 661
Also you need to write a Rewrite Rule in the .htaccess, which would be in the DocumentRoot, to get redirected to that corresponding user properly !
██ SparkSupport.Com - The Premier Tech Company
██ Cloud Solutions|Email Infra setup|VOIP|Video Streaming|Software Development
██ Email: info@sparksupport.com █ Phone : 1- 408-600-1449 | Skype : shijils
-
08-24-2007, 08:45 AM #5WHT Addict
- Join Date
- Jun 2006
- Posts
- 115
:x I dont want it to redirect, i just want it to use the dynamic document root... Can someone show me the Mod Rewrite rule?
Thank you in advance again
-
08-24-2007, 11:04 AM #6Local tech for Los Angeles
- Join Date
- Feb 2003
- Location
- Panorama City, CA
- Posts
- 2,581
Take a look at what these guys provide http://www.lifetype.net/ should put you in the right direction.
-
08-24-2007, 12:57 PM #7WHT Addict
- Join Date
- Jun 2006
- Posts
- 115
... Thats blogging software... Why would you even post that?
-
08-24-2007, 01:02 PM #8Web Hosting Master
- Join Date
- Jan 2006
- Location
- Athens, Greece
- Posts
- 1,481
Probably he wanted to take a look at the .htaccess file.
-
08-24-2007, 01:47 PM #9Local tech for Los Angeles
- Join Date
- Feb 2003
- Location
- Panorama City, CA
- Posts
- 2,581
-
08-24-2007, 02:08 PM #10Junior Guru
- Join Date
- May 2007
- Location
- Saint Louis
- Posts
- 194
you could simply add a ln -s in the docroot for each user
ln -s /docroot/usersdirectory /docroot/username.domain.com
-
08-24-2007, 02:46 PM #11Web Hosting Master
- Join Date
- Jan 2006
- Location
- Athens, Greece
- Posts
- 1,481
According to the Apache docs this is what you are looking for:
Code:RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.[^.]+\.host\.com$ RewriteRule ^(.+) %{HTTP_HOST}$1 [C] RewriteRule ^www\.([^.]+)\.host\.com(.*) /home/$1$2
-
08-24-2007, 02:47 PM #12WHT Addict
- Join Date
- Jun 2006
- Posts
- 115
Solution:
Code:UseCanonicalName off ServerAlias *.domain.com ServerName *.domain.com RewriteEngine On # Skip www.domain.com RewriteCond %{HTTP_HOST} !^www\. RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com RewriteRule ^/(.*)$ /home/allusers/%1/$1 [L] DocumentRoot /home/allusers/$1
Note: it helps to play w/ the rewrite conditions and then watch the log file -Code:tail -f /var/log/httpd/error-log
-
08-24-2007, 03:05 PM #13Web Hosting Master
- Join Date
- Jan 2006
- Location
- Athens, Greece
- Posts
- 1,481
I've tried that but it didn't worked. It was pointing me to the host's root directory.
-
08-24-2007, 03:30 PM #14WHT Addict
- Join Date
- Jun 2006
- Posts
- 115
What version of apache?
-
08-24-2007, 03:37 PM #15Web Hosting Master
- Join Date
- Jan 2006
- Location
- Athens, Greece
- Posts
- 1,481
Well, as always.... I had the lines inside the <Directory></Directory>.
Moved it to <VirtualHost> and it's fine now.
RewriteCond %{HTTP_HOST} ^(.*).domain.com$ [NC]
RewriteCond %1 !^(www|ftp)$ [NC]
RewriteRule ^/(.*)$ /%1/$1 [L]
Like this you can exclude www,ftp or other 3rd level domains.
-
08-24-2007, 03:57 PM #16WHT Addict
- Join Date
- Jun 2006
- Posts
- 115
That'll do it