peter
peter

Reputation: 4421

htaccess allow from subdomain

I have restrict rules in htaccess

order deny,allow
deny from all
allow from 111.111.222.222

How could I make something like this?

order deny,allow
deny from all
allow from sub.domain.tld

My IP is changing frequently and I have domain name A DNS record for this IP as sub.domain.tld. This would save me much time when my IP changes because I don't need to change all htaccess files with the new one IP.

I tried it but unfrotunatelly it is not working. Any workaround for this? Many thanks.

Upvotes: 1

Views: 2219

Answers (1)

anubhava
anubhava

Reputation: 786091

Try this rewrite rule in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{REMOTE_HOST} !^sub\.domain\.tld$ [NC]
RewriteCond %{REMOTE_ADDR} !^(11\.22\.33\.44|66\.77\.88\.99)
RewriteRule ^ - [F]

Upvotes: 1

Related Questions