0

I'm trying to figure out how to direct something like:

abc.domain.com to a folder on that same server, in this example let's use /userdata/abc

So when visiting abc.domain.com you get all the files in /userdata/abc & the domain does not change.

I'm trying to make this as dynamic as possible (.htaccess has been hell though) so that user abc will have their own domain w/ their own content.

Any advice?

Ross The Boss
  • 624
  • 5
  • 17

3 Answers3

0

Try something like this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^abc.domain.com
RewriteRule ^(.*)$ http://example.com/subdomains/userdata/$1 [L,NC,QSA]
Phil Young
  • 1,334
  • 3
  • 21
  • 43
  • This doesnt save the domain name with the abc subdomain it just redirects to that other url. I want it to load the content of the sub directory & keep the sub domain url. – Ross The Boss Jul 25 '14 at 02:27
0

I do not know what you have in your user directory, but it should work more or less an so..

index.php in main directory

 <?php

      $url = $_SERVER['HTTP_HOST'];
      $array=parse_url($url);
      $array['host']=explode('.', $array['host']);

      $user = $array['host'][0];

      if($user)
      {
           require_once("/userdata/{$user}/index.php";
      }
      else
      {
          // display main page
      }

 ?>

a /userdata/USER/index.php is normal php/html page

ryrysz
  • 907
  • 5
  • 11
  • If no one else comes up with a better answer, ill give it to you, but this is assuming that its a batch of lamp files., which is not the case. – Ross The Boss Jul 25 '14 at 12:21
0

Here is the solution: .htaccess rewrite subdomain to directory

So basically :

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} subdomain\.domain\.com
RewriteCond $1 !^userdata
RewriteRule (.*) /userdata/subdomain/$1 [L]

This gets the content of /userdata/subdomain w/o changing the url. So subdomain.domain.com = the content of /userdata/subdomain/

Community
  • 1
  • 1
Ross The Boss
  • 624
  • 5
  • 17
  • It's the same link that I written in first comment ;) – ryrysz Jul 25 '14 at 17:45
  • Yes. But A. Not specific to question & B. I dont know how to choose another answer from another question as answer. You should get the credit, but your current answer assumes a lot. – Ross The Boss Jul 25 '14 at 20:19