Say I have an app at example.com.
One customer migth have it's content in example.com/customer/hisname/
.
Well, I would like to make possible that the customer assigns a domain for his content, say hisname.com
, so this (hisdomain.com) renders example.com/customer/hisname/
.
To do that I have created two virtual hosts, both having the root directory in the same place, and I have written a .htaccess file in order to filter the http_host and if not example.com then rewrite in such manner that it passes the request to example.com/customer/hisname/.
Still, this approach doesn't work while I do not get the /customer/hisname/ part in URI. If I go to hisname.com/list/ in the example.com/index.php, where I would need to have both /list/ and (as a prefix) /customer/hisname/, I only get, as you might expect just /list/.
So, what would be the right approach for this?
If you can create Virtual Hosts, you should set the proper document root instead of using mod_rewrite
If this is not possible, you can extract the
host
part and do an internal rewriteuse the variable $_SERVER['HTTP_HOST'] and load a different view depending on the host requested. Make sure you handle all subhosts needed and have a default page as well