: How can I make all created directories assign to a subdomain? So we have a .php file that creates a directory that is named after user input from a form, and uses file_put_contents to have
So we have a .php file that creates a directory that is named after user input from a form, and uses file_put_contents to have a n index.php already in that directory. Our problem is that it can be only accessed by website.com/domain instead of domain.website.com. How would I automatically assign a subdomain with the same name to the directory? We have tried just about everything the internet will give us, and have been stuck for 3 hrs. We are using Apache on Debian.
More posts by @Radia820
1 Comments
Sorted by latest first Latest Oldest Best
You can't create a subdomain using only PHP application.
First you need to configure apache virtual host to accept requests for multiple domains.
<VirtualHost *:80>
ServerName example.com ServerAlias example.com *.example.com
DocumentRoot /www/domain
</VirtualHost>
With wildcard subdomain *.example.com, main domain will receive all requests for any sub-domain, which can be handled by either using .htaccess or with PHP application.
Now, use htaccess code to rewrite URL i.e. load subdirectory on subdomain URL,
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} =subdir.example.com
RewriteCond %{DOCUMENT_ROOT}/subdir/%{REQUEST_URI} -f
RewriteRule ^(.+) %{DOCUMENT_ROOT}/subdir/ [L]
</IfModule>
** need to write more generic htaccess code.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.