htaccess: Allow from domain name instead of IP/subnet

一曲冷凌霜 提交于 2021-02-18 08:42:08

问题


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.


回答1:


Yes you can. Your .htacces would look like

order deny,allow
deny from all
allow from mysite.com



回答2:


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




回答3:


protect a folder:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://([a-z0-9-]+\.)*your-domain.com/ [NC]
RewriteRule /* http://%{HTTP_HOST}/ [R,L]


来源:https://stackoverflow.com/questions/28376037/htaccess-allow-from-domain-name-instead-of-ip-subnet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!