PDA

View Full Version : subdomains


xinn
12-03-2005, 06:56 AM
Hello,
so far ive been setting up different vhosts for different subdomains. In near future, i will have to create 100+ small pages in one domain but on different subdomains. Here is my question. Is this possible to create one vhost to handle these subdomains? The rule should be:
domain.com : /home/domain/www/
sub1.domain.com /home/domain/www/sub1/
sub2.domain.com /home/domain/www/sub2/

Regards
Xinn

mistwang
12-03-2005, 09:26 AM
Yes, you can use some simple rewrite rules to do it.
You can reference section "Simple dynamic virtual hosts using mod_rewrite" in
http://httpd.apache.org/docs/1.3/vhosts/mass.html

xinn
12-03-2005, 11:24 AM
Simple rules means a lot of work for me ;)
I tried some configurations mentioned on this site... But they dont work for me..

This one would be ideal for me:


RewriteEngine on

RewriteMap lowercase int:tolower

# allow CGIs to work
RewriteCond %{REQUEST_URI} !^/cgi-bin/

# check the hostname is right so that the RewriteRule works
RewriteCond ${lowercase:%{SERVER_NAME}} ^www\.[a-z-]+\.domain\.pl$

# concatenate the virtual host name onto the start of the URI
# the [C] means do the next rewrite on the result of this one
RewriteRule ^(.+) ${lowercase:%{SERVER_NAME}}$1 [C]

# now create the real file name
RewriteRule ^www\.([a-z-]+)\.domain\.pl/(.*) /home/domain/public_html/$1


Any ideas how to force it to work? ;)

mistwang
12-03-2005, 01:19 PM
There is a bug in rewritemap will be fixed in next release, but you don't need to use the lowercase map, as the %{SERVER_NAME} has been converted to lowercase by LSWS already, so you can try:

RewriteCond %{SERVER_NAME} !^www\.us\.pl$
RewriteCond %{SERVER_NAME} ^(.*)\.us\.pl$
RewriteRule ^/(.*)$ /home/uspl/public_html/%1/$1

Set "Rewrite Log level" to "9" and check the error log to debug those rules.
[/code]

xinn
12-03-2005, 03:31 PM
Hello,

thank you for your answer Goerge,

the rules which you wrote almost fits my needs, there is just small *bug*,
when you access www.sub.domain.pl it searchs for files in:
/home/user/public_html/www.sub not in /home/user/public_html/sub

This rule works perfect ( maybe someone other will use it in future - this is why i post it here ):


RewriteCond %{SERVER_NAME} !^www\.domain\.pl$
RewriteCond %{SERVER_NAME} ^(www\.)?([a-z-]+)\.domain\.pl$
RewriteRule ^/(.*)$ /home/domainpl/public_html/%2/$1


Thank you for your help Mistwang,

Best Regards
xinn