Is there a cleaner way to do this?
I’m interested in updating the file with a list via a script that will run periodically with allowed IP addresses.
the logic is:
If {REMOTE_ADDR} = (1.2.3.4|2.3.4.5|3.4.5.6|192.168.0.0/24)
do nothing
Else
Redirect them 301 to the current website.
I’ve tried the following test:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# Redirect all except allowed IP
RewriteCond %{REMOTE_ADDR} !^123.456.789.101$
ReWriteCond %{REMOTE_ADDR} !^234.567.891.011$
RewriteRule (.*) http://Currentwebsite.com/$1 [R=301,L]
You need the redirect stuff to happen before your wordpress rules. Because wordpress routes everything to index.php, the request gets mangled before the redirect: