WordPress redirect all except my IP

I have two wordpress websites NEW and OLD with permalinks. The OLD website is locatet at http://website.com/old and the NEW is located at http://website.com.

I want to redirect all exept my IP to the OLD website (http://website.com/old) using .htaccess.

Read More

The default .htaccess located at the main directorie (http://website.com) is:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

I’ve changed this to the following (where xx.xxx.x.xxx is my IP):

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^xx.xxx.x.xxx
RewriteRule .* http://website.com/old [R=302,L]
</IfModule>

At this point I can redirect all to the OLD website exept my IP. The problem is when I navigate to any page on my NEW website like http://website.com/contacts it retuns:

Not Found
The requested URL /contacts/ was not found on this server.
Apache Server at website.com Port 80

Any idea? Thanks

Related posts

Leave a Reply

1 comment

  1. You must keep WordPress’ main rule after your IP-check

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    # if not my ip then redirect to old version
    RewriteCond %{REMOTE_HOST} !^xx.xxx.x.xxx$
    RewriteRule . old [R=302,L]
    
    # if we're here, it means it's me so display new version
    RewriteRule ^index.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]
    </IfModule>