.htaccess point a subdomain to a directory


I have the following directory structure:


- index.php

- desktop/

-- index.php

- mobile/

-- index.php

The index.php of site.com redirects to desktop/index.php or mobile/index.php, depending of user platform.

The problem is that I need different subdomains to point to respective directories:

mobile.site.com -> site.com/mobile

desktop.site.com -> site.com/desktop

My application also uses rewrite to make SEO friendly URL’s, so I need:

mobile.site.com/login -> site.com/mobile/login

mobile.site.com/user/1 -> site.com/mobile/user/1


Any suggestion how to do this?

Thanks in advance.

Htaccess cannot help you to map something like domain.com/mobile to mobile.domain.com (unless you are using DNS wildcards, smth like *.site.com => site.com)

What you need, is to create s subdomain with the help of virtual hosts in apache and make the document root for that vhosts to point to /var/www/site.com/mobile , so you’d have smth like

<VirtualHost *:80>

ServerName mobile.site.com

ServerAlias mobile.site.com

DocumentRoot /var/www/site.com/mobile


Then, inside the mobile folder, you will have a .htaccess file, with the RewriteBase set to /

The rest can be accomplished from within Yii urlManager component.

How didn’t I remeber that before? Thanks!

Have you done it yet? please guiding me, I’m still vague about that.