Gonçalo Basto
Gonçalo Basto

Reputation: 51

.htaccess point a subdomain to a directory

I have the following directory structure:

site.com/
- 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 to .htaccess file?

Thanks in advance.

Upvotes: 0

Views: 953

Answers (2)

Srikanta
Srikanta

Reputation: 1

Try this

RewriteCond %{HTTP_HOST} ^(.*).site.com$

RewriteRule (.*) %1/$1 [L]

Upvotes: 0

Rich Bowen
Rich Bowen

Reputation: 202

RewriteCond %{HTTP_HOST} ^mobile RewriteRule ^/?(.*) /mobile/$1 [PT,L]

RewriteCond %{HTTP_HOST} ^desktop RewriteRule ^/?(.*) /desktop/$1 [PT,L]

On the other hand, if you want to redirect, rather than just pass-through, change that PT to an R in each case.

Upvotes: 1

Related Questions