Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

EbrahemSamer's avatar

How to make a subdomain like sa.domain.com and display specific data on it ? PHP

I've website ex: ( domain.com ) displays products and I wanna make subdomain like ( sa.domain.com ) to display products that in "Saudi Arabia" for example.

How to make this subdomain and make it display only specific data from the original website domain.com...

I can copy all website to the subdomain but I think there is a better idea ??? PHP Native

0 likes
7 replies
automica's avatar

@ebrahemsamer if you have multiple subdomains you can point them all to the same root directory and then use

$_SERVER['HTTP_HOST']

to determine which host is being accessed and filter your products that way.

If its laravel, then there are more elegant solutions.

1 like
siangboon's avatar

Laravel do have Subdomain Routing https://laravel.com/docs/8.x/routing#route-group-subdomain-routing

But, creating a new or updating existing subdomain will involve DNS record changes and it will take from hour up to 72 hours to propagation to all the world...

i think i would prefer to use middleware to update the region/country and store it in session or somewhere to filter the data without touching the dns part...

Phread's avatar

Maybe I am missing the question, but it seems as if you could have the domains point/use the same database, each domain defining the specific qualification(s) you want.

Define the qualification's value in either the .env file OR in the config/app.php file (preferred choice) This would allow you to specify the qualification for each of your domains you currently have and may add in the future.

And, for the domains which would not have any specific qualification(s) you could have it defined as "1=1" in .env or config/app.php.

siangboon's avatar

overlook the last 2 words...

still, allow user to select their own region/country may be more preferable for me...

automica's avatar

@ebrahemsamer don't redirect the subdomains. Set them to point to the same document root as your primary domain.

eg

<VirtualHost www.company.com>
DocumentRoot /path/to/main/documentroot
    ServerName site1.company.com
</VirtualHost>

<VirtualHost subdomain1.company.com>
DocumentRoot /path/to/main/documentroot
    ServerName subdomain1.company.com
</VirtualHost>

<VirtualHost subdomain2.company.com>
DocumentRoot /path/to/main/documentroot
    ServerName subdomain2.company.com
</VirtualHost>
1 like

Please or to participate in this conversation.