.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