-1

How can I do that when a user enters to a subdomain (I'll have wildcard subdomains), he will see what in the subfolder with the same name in the main domain? For example, if user will enter to works.domain.com, I want him to see what's in www.domain.com/works.

Here is my approach:

  1. I have created a wildcard subdomain like *.domain.com
  2. Created some subdomain into the wildcard directory with a index.php file as I can check preferences other information about this store -> see:

enter image description here

  1. Now my intention is to provide the user what they ask for in the url

This code is written in wildcard/index.php file

  <?php 

 //Get the store name from url
 $host = $_SERVER['HTTP_HOST'];
 $url = explode('.', $host)[0];

 //Find the store name is it available in the database
 $db      = new database;
 $qri     = $db->query("SELECT * FROM store_info WHERE store_name='$url'");
 $count   = mysqli_num_rows($qri);

 //If it returns true then show the reuquested store data
 if($count != 0){
   *I want to show here the folder data that requested in the url*
 }else{
   echo 'Store Not found';
 }

Now my question is:

  1. Is it the right approach to do it,so how can I show the requested folder data?
Mmd Mahbub
  • 53
  • 1
  • 10

1 Answers1

0

You can configure NGINX in front of your PHP server to route to particular directories with the following configuration (not tested). Configuring this in NGINX would be efficient than configuring this in PHP.

server {
      server_name ~^(?<sub>[a-zA-Z0-9-]+)\.domain\.com$; # will cause the sub-domain to be placed in $sub
      return 301 "http://testsite.net/${sub}${uri}";
    }

Source: https://serverfault.com/questions/426673/nginx-redirect-subdomain-to-sub-directory

Kaushik Wavhal
  • 600
  • 1
  • 9
  • 18
  • But I need to check few more things like there subscription type/billings etc as I can determine whether they are eligible or not to use the store. I mean if they don't pay the bills then I can show them as there store deleted or expired – Mmd Mahbub Dec 23 '18 at 19:37
  • you can handle that in your PHP code as you were intending to do. That URI param should forward your original URI data to the new redirected URL. – Kaushik Wavhal Dec 23 '18 at 21:49
  • should i write it on a. htaccess file the code u provided? – Mmd Mahbub Dec 24 '18 at 04:33