htaccess: Allow from domain name instead of IP/subnet
15,538
Solution 1
I came across this because I had the same problem.
Just in case anyone else finds this, I found the perfect solution:
Beginning in Apache 2.4.19, you can use the parameter "Require forward-dns [hostname]", which simply allows all IPs behind [hostname].
https://httpd.apache.org/docs/2.4/mod/mod_authz_host.html#requiredirectives
Solution 2
Yes you can. Your .htacces would look like
order deny,allow
deny from all
allow from mysite.com
Comments
-
Bijan almost 2 years
On my Authentication page i have it only allow from certain IPs. Is it possible to have it allow by a domain name? The IP of my home network is dynamic but the domain name (mysite.com) always points to the correct IP address.
-
Bijan about 9 yearsThat did not seem to work. Is there a way to debug this?
-
Ravi K Thapliyal about 9 yearsBasically, this method needs that your web host has enabled reverse domain lookups and even then it may not work depending on what domain is actually getting reported to Apache. Read gossamer-threads.com/lists/apache/users/353517 for more info. I would suggest, you switch to using password protection (htpasswd).
-
Mengseng Oeng about 2 yearsIt's does not work.