Gurus of So

I have a simple .htaccess file where I only redirect non www to www for my webapp. Now what I want to do is

  1. Create a new vhost like http://subdomain.mydomain.tld
  2. Create a redirect for anybody coming to that subdomain to a folder on my app like app/webroot/subdomain

My current .htaccess looks like this

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www\.mydomain\.tld [NC]
    RewriteRule ^(.*)$ http://www.mydomain.tld/$1 [R=301.L]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ app/webroot/$1 [QSA,L]
</IfModule>

How would I go about it? Can I do this all in my .htaccess file or do I need to mess with GoDaddy as well? I rather not do this in the app, if that makes sense.

I am running Ubuntu 10.04 + Apache 2.2.14-5

Thanks


Solution 1:

Here's what you need to put in your .htaccess file:

RewriteEngine on
# redirect mydomain.tld to www.mydomain.tld
RewriteCond %{HTTP_HOST} ^mydomain\.tld [NC]
RewriteRule ^(.*)$ http://www.mydomain.tld/$1 [R=301,L]

# default website
RewriteCond %{HTTP_HOST} ^www\.mydomain\.tld$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app/webroot/$1 [NC,QSA,L]

# subdomain to folder
RewriteCond %{HTTP_HOST} ^(sub|subfolder)\.domain\.com$ [NC]
RewriteCond %1 !^www$ [NC]
RewriteRule ^(.*)/?$ http://www.domain.com/%1/$1 [NC,QSA,L]