I'm using this code to allow only my ip to access the site
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^xxx\.xxx\.xxx\.xxx
RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintenance.html [R=302,L]
</IfModule>
Now I would like to allow my friends ip to access the site. How to specify multiple ips in htaccess?
Use an .htaccess file to restrict the site and add:
#...
Allow from IP/SubnetMask
Allow from IP/SubnetMask
#...
See documentation for more details.
The trick is to add a rule that does nothing for the allowed IPs, than to add the rule for the maintenance; as you can mark the rule as Last, which means next rules won't be processed (unless the rule didn't modify the address, which will trigger one more pass trough the .htaccess). In your case it will look like:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REMOTE_ADDR} xxx\.xxx\.xxx\.xxx [OR]
RewriteCond %{REMOTE_ADDR} xxx\.xxx\.xxx\.xxy [OR]
RewriteCond %{REMOTE_ADDR} xxx\.xxx\.xxx\.xxz
RewriteRule .* - [L] #do notthing
#if we are here, the IP is not in the allowed list, redirect
RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintenance.html [R=302,L]
</IfModule>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With