views:

45

answers:

1

.htaccess:

RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{QUERY_STRING} !^id=.
RewriteRule (.*) /index.php?id=%1 [L]

Expected behavior:

If there is a subdomain (test.example.com) it goes to the folder /service/ and if there isn't it goes to the folder /site/.

Example behavior:

test.example.com/post?id=2 -> public_html/service/post.php?id=1
test.example.com/category?id=3 -> public_html/service/category.php?id=3

example.com/register.php -> public_html/site/register.php
A: 

Try these rules:

RewriteCond %{HTTP_HOST} !=www.example.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$
RewriteRule !^service/ service/index.php?id=%1 [L]

RewriteCond %{HTTP_HOST} =example.com
RewriteRule !^site/ site%{REQUEST_URL} [L]
Gumbo