1

In my platform, each user has their own config file. The file is named by the subdomain they created.

Example:

user1.domain.com
user2.domain.com
user3.domain.com

The system reads the url via $_SERVER['SERVER_NAME'] and grabs the subdomain. It then looks up the appropriate config file based off of the subdomain.

Example:

if the url is user1.domain.com the system looks up user1.config.php.

Each users has the option to use there own domain. I am currently doing this by pointing the A record.

Example:

user 1 points theirDomainName.com to my IP address via their A record

how can I use htaccess so the url reads theirDomainName.com but backend of the platform (php) reads user1.domain.com thus the platform knows to pull the user1.config file

6
  • You'll need to map it one place or another so you might as well just map them in the main PHP script. Jun 17, 2016 at 18:05
  • Can you explain?
    – Jason
    Jun 17, 2016 at 18:08
  • Make an array in PHP that maps the domain name to the username so you'll know how to do your include. If you're afraid of correcting the existing script beyond that, you could even update $_SERVER['SERVER_NAME'] based on it. Jun 17, 2016 at 18:24
  • Possible duplicate of How to create a CNAME for a domain's root name
    – Sherif
    Jun 17, 2016 at 18:37
  • Your question is basically asking "How do I create a CNAME for theirDomainName.com" whch is a duplicate of serverfault.com/questions/62527/…
    – Sherif
    Jun 17, 2016 at 18:37

1 Answer 1

0

Instead of making rewrite rules in .htaccess, it would be much simpler to maintain by doing the mapping inside your PHP script.

That array should map the domain name to the username so you'll know how to do your include. If you're afraid of correcting the existing script beyond that, you could even update $_SERVER['SERVER_NAME'] based on it.

You could, for example, do: 'user1.domain.com', 'domain2.com'=>'user2.domain.com', 'domain3.com'=>'user3.domain.com'];

if (!array_key_exists($_SERVER['SERVER_NAME'], $clients)) {
    header('Location: http://domain.com/invalidclient');
    exit;
}

$_SERVER['SERVER_NAME'] = $clients[$_SERVER['SERVER_NAME']];

While it is not in the best practices to overwrite super globals, nothing prevents it and it gives you a really simple solution.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .