Wildcard Subdomains

后端 未结 8 918
广开言路
广开言路 2020-12-07 15:25

I know there have been a few threads on this before, but I have tried absolutely everything suggested (that I could find) and nothing has worked for me thus far...

W

8条回答
  •  长情又很酷
    2020-12-07 16:00

    I had to do exactly the same for one of my sites. You can follow the following steps

    1. If you've cPanel on your server, create a subdomain *, if not, you'd have to set-up an A record in your DNS (for BIND see http://ma.tt/2003/10/wildcard-dns-and-sub-domains/). On your dev. server you'd be far better off faking subdomains by adding each to your hosts file.

    2. (If you used cPanel you won't have to do this). You'll have to add soemthing like the following to your apache vhosts file. It largely depends on what type of server (shared or not) you're running. THE FOLLOWING CODE IS NOT COMPLETE. IT'S JUST TO GIVE DIRECTION. NOTE: ServerAlias example.com *.example.com is important.

        
              DocumentRoot /var/www/  
              ServerName example.com  
              ServerAlias example.com *.example.com  
      
      
    3. Next, since you can use the PHP script to check the "Host" header and find out the subdomain and serve content accordingly.

提交回复
热议问题