Subdomain hosting on Apache
I am beginne开发者_Python百科r in web server related stuff.
I have a server already working with the domain www.example.com
I want to also host test.example.com
on the server which would also have the same behavior as www.example.com
. That is, all the requests to test.example.com should be mapped to a start.php file.
Also the domain name should remain test.example.com
, i.e. I don't want to redirect requests from test.example.com
to www.example.com
.
How do I achieve this?
Your solution is a name-based virtual host.
Specifically, you want to set up a virtual host to direct requests to a specific host (in this case, identified by a subdomain) to a particular directory. Thereafter, just rewrite requests to start.php
.
<VirtualHost *>
ServerName mysub.domain.tld
DocumentRoot /www/vhosts/http/mysub.domain.tld
RewriteEngine On
RewriteRule ^(.*)$ start.php [L]
</VirtualHost>
Place this in your Apache configuration file or into a separate file in the sites-available
directory, enabling it via a2ensite
. Make sure this one is loaded before the one for domain.tld
, or else Apache will recognize the path to domain.tld
and forget about mysub.domain.tld
.
Restart Apache, and you should be good to go.
精彩评论