Forum Moderators: phranque
After rampaging on google for a while trying to find the solution, I have found the userbase here to be pretty knowledgeable so here I come with my query!
I have written my httpd.conf in Apache to serve multiple domains, ok no problem.
However, I want to make it so that on every domain my server handles, if the subdomain 'admin' is selected, the system loads a path of my choosing.
I thought about creating a seperate VirtualHost directive in httpd.conf however it only seems to review the directive for the domain in question, which would mean adding a seperate entry for every subdomain.
So, either i'm doing something wrong (likely) or my httpd.conf requires further configuration?
Any help is appreciated :)
The only thing that comes to mind is to point all servers to the same DocumentRoot, and then use mod_rewrite to implement Mass Virtual Hosting, as described in the Apache URL Rewriting Guide [httpd.apache.org]. You could add an exception to the example code, so that your subdomains are handled separately, and pointed to a common directory.
Do be aware that unless you take measures to prevent it, pointing multiple hostnames (subdomains in this case) to the same content will result in duplicate-content issues with the search engines. This can result in ranking power being 'split' across the multiple subdomains, a seemingly-randomly-selected subdomain showing up for each of the common URL-paths (selected by the search engines, and beyond your control), or an actual penalty, depending on the number of duplicated URLs. I suggest that you allow only one (or none) of these common subdomains to be crawled by search robots.
Jim
Thanks for the response.
The main reason I want to do this is for shared applications, such as QMailAdmin and phpMyAdmin. The applications will never change and search indexing is simply not an issue.
The more I think of it though, it might just be easier to go with a subdirectory rather than a subdomain!
Thanks again.
Paul
Gave this a shot, but doesn't seem to be taking effect;
RewriteCond %{HTTP_HOST} ^([^.]+).example.com$
RewriteCond %{1} !^(www)$
RewriteCond /data/clientapps/%1 -d
RewriteCond %{REQUEST_FILENAME} !^/data/clientapps/
RewriteRule (.*) /data/clientapps/%1/$1 [Last]
This should rewrite *.example.com to /data/clientapps/*
i.e. if someone goes to [mail.example.com...] the documentroot should be loaded as /data/clientapps/mail.
Unfortunately, this doesn't work! Any ideas?
Thanks
Paul
[edited by: jdMorgan at 1:04 pm (utc) on Sep. 18, 2008]
[edit reason] Please use example.com only [/edit]
Addressing those issues:
RewriteCond $1 !^data/clientapps/
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteCond %1 !^www$
RewriteCond %{DOCUMENT_ROOT}/data/clientapps/%1 -d
RewriteRule ^/(.*)$ /data/clientapps/%1/$1 [L]
The most troublesome part of rulesets like this has to do with getting the correct path for use in 'exists' checks. You can often see the path the exists check is trying to use in the server error log and/or the rewritelog. If you have any trouble, comment out that line first and re-test.
Jim
[edited by: jdMorgan at 1:30 pm (utc) on Sep. 18, 2008]