I have a domain in my HOSTS file;

www.mytestbusiness.com

However, I want to convert some folders into subdomains automatically, e.g.

  • www.mytestbusiness.com/birmingham

  • www.mytestbusiness.com/london

which should be:

  • www.birmingham.mytestbusiness.com

  • www.london.mytestbusiness.com

Only for some folders do I want to keep it as a domain/folder link, e.g.

www.mytestbusiness.com/styles/

I don't want the CSS folder becoming a subdomain, or certain folders like cgi-bin, dwoo etc. (dwoo contains the site templates!)

I am running Apache 2.2 on Windows 7 Home Edition, and the site has no issues, it's just creating subdomains in .htaccess without having to manually declare them which is the problem.

What's the best way to do this, other than manually declaring them in httpd-vhosts.conf as I used to do?

I can't do DNS stuff since this is only on localhost, so what's the best way forward? This is the httpd-vhosts.conf file:

<VirtualHost *:80>
ServerName  mytestbusiness.com
ServerAlias  www.mytestbusiness.com
DocumentRoot /www/vhosts/mytestbusiness.com
ErrorLog /www/Apache22/logs/error.log

<Directory "/www/vhosts/mytestbusiness.com">
    Options All
    AllowOverride All
    order allow,deny
    allow from all
</Directory>

Thanks

link|improve this question
You cannot configure name-based virtual hosts in .htaccess. – beans Feb 14 '11 at 16:17
feedback

1 Answer

If follow what you're trying to do.

In the root .htaccess:

RewriteEngine On
#this should reirect requests to the desired subdomain    
RewriteCond %{HTTP_HOST} ^(www\.)?mytestbusiness\.com$ [NC]
RewriteRule (birmingham|london)/(.*) http://www.$1.mytestbusiness.com/$2 [R=301]

#This should rewrite requests for the subdomain to the correct folder.    
RewriteCond %{HTTP_HOST} ^(www\.)?(birmingham|london)\.mytestbusiness\.com [NC]
RewriteRule (.*)  %1/$1 [L]
#add new rules or tweak these to allow for the other folders you want to redirect
#You'll need to add the appropriate domains to your hosts file

In the config you'll need to add something like:

ServerAlias  *.mytestbusiness.com
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.