Internal subdomain for folder redirection

I want to create folders on the fly, but it looks like I'm creating subdomains on the fly using mod_rewrite. eg.

Create "john" folder using PHP

www.example.com/john/ 

Then get access to what I installed there:

 john.example.com 

Thank you in advance,

Kris

+4
source share
1 answer

First you need to configure the server to accept any subdomain for the example.com domain and redirect it to your virtual host, which should also accept any subdomain. After that, you can use the following rule to rewrite this subdomain inside a folder with the same name:

 RewriteEngine on RewriteCond %{HTTP_HOST} !^www\. RewriteCond %{HTTP_HOST} ^([^/.]+)\.example\.com$ RewriteRule ^ %1%{REQUEST_URI} [L] 
+8
source

Source: https://habr.com/ru/post/1285867/


All Articles