How to add wildcard in / etc / hosts?

Recently, I wanted to point all subdomains for a test domain, say example.com to localhost. Is there a way to point all requests to * .example.com to resolve 127.0.0.1

+56
hosts
Dec 07 '13 at 21:32
source share
2 answers

It happens that the /etc/hosts does not support wildcard entries.

You will have to use other services, such as dnsmasq. To enable it in dnsmasq, simply edit dnsmasq.conf and add the following line:

 address=/example.com/127.0.0.1 
+67
Dec 07 '13 at 21:32
source share

Here is the configuration for those who are trying to fulfill the original goal (wildcards pointing to the same code base - do not install anything, dev environment, i.e. XAMPP)

hosts file (add entry)

file: / etc / hosts (non-windows)

 127.0.0.1 example.local 

Httpd.conf configuration (enable vhosts)

file: /XAMPP/etc/httpd.conf

 # Virtual hosts Include etc/extra/httpd-vhosts.conf 

Httpd-vhosts.conf configuration

file: XAMPP / etc / extra / httpd-vhosts.conf

 <VirtualHost *:80> ServerAdmin admin@example.local DocumentRoot "/path_to_XAMPP/htdocs" ServerName example.local ServerAlias *.example.local # SetEnv APP_ENVIRONMENT development # ErrorLog "logs/example.local-error_log" # CustomLog "logs/example.local-access_log" common </VirtualHost> 

restart apache

create pac file:

save as whatever.pac wherever you want, and then upload the file to your browser> proxy> autoconfiguration settings (reload if you change this)

 function FindProxyForURL(url, host) { if (shExpMatch(host, "*example.local")) { return "PROXY example.local"; } return "DIRECT"; } 
+6
Aug 19 '14 at 19:51
source share



All Articles