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

Tim
  • 30,383
  • 6
  • 47
  • 77
Jason
  • 113
  • 3
  • You'll need to map it one place or another so you might as well just map them in the main PHP script. – Julie Pelletier Jun 17 '16 at 18:05
  • Can you explain? – Jason Jun 17 '16 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. – Julie Pelletier Jun 17 '16 at 18:24
  • Possible duplicate of [How to create a CNAME for a domain's root name](http://serverfault.com/questions/62527/how-to-create-a-cname-for-a-domains-root-name) – Sherif Jun 17 '16 at 18:37
  • Your question is basically asking "_How do I create a CNAME for `theirDomainName.com`_" whch is a duplicate of http://serverfault.com/questions/62527/how-to-create-a-cname-for-a-domains-root-name – Sherif Jun 17 '16 at 18:37
  • @JuliePelletier thank you. make it an answer and I will uptick it – Jason Jun 17 '16 at 18:42

1 Answers1

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.

Julie Pelletier
  • 1,000
  • 6
  • 8