views:

833

answers:

4

I have a wildcard subdomain enabled and dynamically parse the URL by passing it as-is to my index.php (ex. somecity.domain.com).

Now, I wish to create a few subdomains that are static where I can install different application and not co-mingle with my current one (ex. blog.domain.com).

My .htaccess currently reads:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Can I manipulate this .htaccess to achieve what I need? Can it be done through Apache? How?

A: 

You'll have to configure apache for those static sub-domains. The "catch-all" site will be the default site configured, so that one will catch the other ones.

changelog
A: 

I'm not sure I understand completely what you need to accomplish, but it might helpful to setup virtual domains within your Apache configuration file. You can map them to folders on the drive with different applications installed. Each virtual domain is treated much like a root directory. I have my development environment setup locally on my Windows machine a lot like this:

NameVirtualHost *:80

# Begin virtual host directives.

<VirtualHost *:80>

# myblog.com virtual host.

ServerAdmin [email protected]
DocumentRoot "c:/apache_www/myblog.com/www"
ServerName myblog.com
ServerAlias *.myblog.com
ErrorLog "c:/apache_www/myblog.com/logs/log"
ScriptAlias /cgi-bin/ "c:/apache_www/myblog.com/cgi-bin/"

<Directory "c:/apache_www/myblog.com/www">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

</VirtualHost>

If this does not help get you on the right track, then try researching the VirtualHost directive to come up with a solution. I find trying to do all this in an .htaccess to be cumbersome and difficult to manage.

hal10001
+1  A: 

Your .htaccess does nothing useful, as Apache is probably configured with DirectoryIndex index.php. Well, it does move domain.com/a to domain.com/index.php, but I doubt that is what you want.

Your wildcard virtualhost works because you probably have ServerAlias *.domain.com in your configuration, or a single virtualhost and DNS pointing to the address of your server. (When you have a single virtualhost, it shows up for any request, and the first listed virtualhost is the default one)

You have to create new VirtualHosts for the static domains, leaving the default one as, well, the default one :)

Check these tutorials that explain it all.

Vinko Vrsalovic
A: 

I don't know if you have cpanel installed on your host, but i was able to do this by adding a new subdomain '*' and then sending all that traffic to a particular subdomain, ex *.domain.com -> master.domain.com. Then you can read out which url you are at in master.domain.com and go from there.

SeanDowney