How to create dynamic subdomain using PHP and htaccess?

前端 未结 2 604
抹茶落季
抹茶落季 2021-01-31 12:37

I have one problem: I want to set up PHP and htaccess to make dynamic subdomains. And I can not figure out how. Currently my URL looks like this:

www.exemple.com         


        
2条回答
  •  温柔的废话
    2021-01-31 12:58

    You can't make dynamic subdomains with .htaccess

    You will need to configure the apache virtual host to accept requests for multiple domains

    See the Apache documentation - Using Name Based Virtual Hosts

    
        ServerName www.example.com
        ServerAlias example.com *.example.com
        DocumentRoot /www/domain
    
    

    Adding the wildcard subdomain *.example.com, your PHP application will receive all requests for any domain below example.com, ie garbage.example.com, busted.example.com, llama.example.com, etc.

    Creating Wildcard Sub Domain Using Apache VirtualHost

    Multiple Domains to One Virtual Host | Wildcard Host (shared hosting)?

    Apache default virtual host for multiple domains

    At this point, your application will have to determine the validity of the subdomain and display the appropriate error for unknown subs.

    From there, parse the domain for mike.

提交回复
热议问题