Wildcard domains with virtualhost with Apache on Mac

后端 未结 2 1312
醉话见心
醉话见心 2021-01-22 12:33

I\'m currently running several domains for local development

http://wordpress.dev
http://phpmyadmin.dev
http://projectx.dev
http://projecty.dev
...
2条回答
  •  囚心锁ツ
    2021-01-22 13:21

    Use mod_vhost_alias and a VirtualDocumentRoot

    As long as you have no VirtualHost catching foo.dev as a ServerName or ServerAlias you should be able to do the following:

    
      ServerName default.dev
    
      VirtualDocumentRoot /Users/youruser/%-2
      ...
      ...
    
    

    You'll need the username to be hardcoded, though you say that's not a problem.

    %-2 in the VirtualDocumentRoot represents the penultimate dot-separated part of foo.com, i.e. foo. You could then have directories as you wish that map to the sites:

    http://foo.dev =>  /Users/youruser/Sites/foo
    http://bar.dev =>  /Users/youruser/Sites/bar
    http://subdom.baz.dev =>  /Users/youruser/Sites/baz
    

    You'll need to make sure that any additional domains you want to map in this fashion have an appropriate entry in your hosts file, or DNS if you're using that.

提交回复
热议问题