How to redirect all visitors except your IP to another website?

July 9, 2021 . 1 MIN READ

Sometimes you may need to redirect your visitors to another website, but still be able to access your website from your IP.

This can easily be done using a .htaccess file. To redirect everyone but you to another website, you should add this code to your .htaccess file:

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^1.2.3.4
RewriteRule .* http://www.anothersite.com [R=302,L]

You should replace the numbers 123 and 4 with the numbers of your actual IP address! You can find what your IP address is at:

http://whatismyip.org/

This will redirect all your visitors to anothersite.com except you

You can achieve the same result by denying access to your website for everyone except you. All other visitors will be redirected to anothersite.com. The rules that should be added to your .htaccess file are:

ErrorDocument 403 http://www.anothersite.com
Order deny,allow
Deny from all
Allow from
 1.2.3.4

 

 

You can simply add 2 Rewrite rules in your .htaccess file:
1) Redirect all visitors except 123.45.67.67 and 123.45.68.68 to domain1.com:

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^123.45.67.67 [OR]
RewriteCond %{REMOTE_HOST} !^123.45.68.68
RewriteRule .* http://www.domain1.com [R=302,L]

2) and the second one – redirect only 123.45.67.67 and 123.45.68.68 to domain2.com:

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} ^123.45.67 [OR]
RewriteCond %{REMOTE_HOST} ^123.45.68
RewriteRule .* http://www.domain2.com [R=302,L]

https://www.siteground.com/kb/how_to_redirect_all_visitors_except_your_ip_to_another_site/

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *