{"id":478,"date":"2020-10-13T12:44:34","date_gmt":"2020-10-13T12:44:34","guid":{"rendered":"https:\/\/mklasen.com\/?p=478"},"modified":"2021-10-23T08:06:06","modified_gmt":"2021-10-23T08:06:06","slug":"wildcard-subdomains-in-mamp-pro-on-macos","status":"publish","type":"post","link":"https:\/\/mklasen.com\/wildcard-subdomains-in-mamp-pro-on-macos\/","title":{"rendered":"Wildcard subdomains in MAMP Pro on MacOS"},"content":{"rendered":"\n
A while back I was debugging the front-end creation of multisites in WordPress. On each install, a new subdomain was created which forced me to add a new alias to the website configuration. The frustration!<\/p>\n\n\n\n
So how do you solve that?<\/p>\n\n\n\n
MacOS does not allow you to add a wildcard subdomain to your Let’s start with installing dnsmasq via brew.<\/p>\n\n\n\n After install, change the config of dnsmasq by running I added this on top of the file.<\/p>\n\n\n\n After customising the configuration, add a resolver; And add the following to the Ready to start the service? Done! All .test traffic is now <\/strong>handled by our localhost. <\/p>\n\n\n\n Finally, MAMP also has to be aware of these changes. In this case I used an NGINX configuration, so I edited the config file via File -> Edit Template -> nginx.conf and added the following part to the server_name parameter for both HTTP and HTTPS websites: So, for HTTP And for HTTPS Done! MAMP now handles all .test traffic and NGINX is configured to handle subdomains as well! Byebye subdomain aliases!<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":" A while back I was debugging the front-end creation of multisites in WordPress. On each install, a new subdomain was created which forced me to add a new alias to the website configuration. The frustration! So how do you solve that? MacOS does not allow you to add a wildcard subdomain to your \/etc\/hosts file […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[1],"tags":[],"acf":[],"yoast_head":"\n\/etc\/hosts<\/code> file so I had to come up with another solution. After a bit of research I found that I could use dnsmasq.<\/p>\n\n\n\n
Send all .test traffic to 127.0.0.1<\/h4>\n\n\n\n
brew install dnsmasq<\/code><\/p>\n\n\n\n
nano $(brew --prefix)\/etc\/dnsmasq.conf<\/code> and adding:<\/p>\n\n\n\n
# --- Added by mklasen\n# Route all *.test addresses to localhost\naddress=\/test\/127.0.0.1\n# Don't read \/etc\/resolv.conf or any other configuration files.\nno-resolv\n# Never forward plain names (without a dot or domain part)\ndomain-needed\n# Never forward addresses in the non-routed address spaces.\nbogus-priv\n# ----<\/code><\/pre>\n\n\n\n
sudo mkdir \/etc\/resolver<\/code>
sudo nano \/etc\/resolver\/test<\/code><\/p>\n\n\n\n
test<\/code> file created above:
nameserver 127.0.0.1<\/code><\/p>\n\n\n\n
sudo brew services start dnsmasq<\/code><\/p>\n\n\n\n
Make MAMP listen to the subdomains, without having to set aliases.<\/h4>\n\n\n\n
~^(.*).MAMP_VirtualHost_ServerName_MAMP$;<\/code><\/p>\n\n\n\n
MAMP_VirtualHost_ServerName_MAMP<\/code>
is replaced byMAMP_VirtualHost_ServerName_MAMP ~^(.*).MAMP_VirtualHost_ServerName_MAMP$<\/code><\/p>\n\n\n\n
MAMP_SSLVirtualHost_ServerName_MAMP<\/code>
is replaced byMAMP_SSLVirtualHost_ServerName_MAMP ~^(.*).MAMP_SSLVirtualHost_ServerName_MAMP$<\/code><\/p>\n\n\n\n