I need to create a temporary .htaccess file on my test server so that only my public dhcp ip can access my test sites.
I have three lines in my .htaccess.
RewriteEngine On
RewriteCond expr "file('%{DOCUMENT_ROOT}/myip') != %{REMOTE_ADDR}"
RewriteRule ^(.*)$ /blackhole2.html [R,L]
The first line reads the output of my php script file written in /myip file. If the address does not match 'remote_addr' then forward to an appropiate webpage. ie: blackhole2.html
It looks like if the ip addresses match I can gain access to my test site. However, if the ip address does not match, the rewrite rule errors with 302 looping errors.
I have tried several flag delimiters etc. but have now thrown my toys out of my I.T. drawer.
What have I overlooked, or not understood what else is required. Thanks.
This triggers a redirect-loop when the IP address does not match because the redirected response to /blackhole2.html is caught by the same rule and redirected to /blackhole2.html again and again....
You need to include an exception for when /blackhole2.html is requested.
For example:
:
RewriteRule !^blackhole2\.html$ /blackhole2.html [R,L]
Or simply block the request (403 Forbidden) and don't redirect:
:
RewriteRule ^ - [F]
Although you will need to create an exception if you have a custom 403 ErrorDocument.