How to create specific virtual domain

requests to should be handled by main.php file on the html root
requests to should be handled by another main.php file which is under “sub” directory (sub/main.php)
so to achieve this, i tried a htaccess file like this:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^sub\\.domain\\.com
RewriteCond %{REQUEST_URI} !^/images/
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} !=/robots.txt
RewriteRule (.*) main.php [L]

RewriteCond %{HTTP_HOST} ^sub\\.domain\\.com
RewriteRule (.*) sub/main.php [L]

but ofcourse this is not working :slight_smile: only rewrite is working properly, but if i try to call, i get 404 error. it’s not going to sub/main.php
i just need this specific subdomain. i searched the forum but there are dynamic subdomain threads…
yes i know i can solve this by creating the subdomain from cpanel. but i need to solve it via htaccess.
maybe the answer will help more people out there…

any ideas anybody?

ok, here is the correct answer:
htaccess should be

RewriteEngine on
RewriteCond %{HTTP_HOST} ^m\\.example\\.com$
RewriteRule ^{REQUEST_URI} [L,P]

but now is there a server performance difference between this htaccess solution and creating subdomain via cpanel?

in this htaccess solution, i used proxy flag in RewriteRule, so it looks like a query is forwarded hiddenly to another http query.
and this can make an extra load to server. this is just a theory, please send your decisions :eye: