1

Redirecting specific IP addresses to a different website. The hosting server is Apache.

I want certain visitors with specific IP address's to be redirected to a different website. I will be adding more over time.

I found:

#Redirect whole networks of IP addresses to an external URL
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^10\.20\.30 [OR]
RewriteCond %{REMOTE_ADDR} ^125\.62
RewriteRule ^folder/(.*) http://anotherdomain.com/folder/$1 [R,L]

Is there any simpler way to do this?

Also, can I redirect 2 different IP addresses to different sites?

Why is ! added before the IP address on some examples of the above?

What does the /$1 do?

Does .htaccess mods work on ip6v addresses?

  • you are using 3 rows correct? – norcal johnny Oct 1 '16 at 3:49
  • Your edits completely change the question being asked, and hence impacts the answer already received, so it's being rolled back. Please ask another question specific to redirecting IPv6 addresses. – dan Oct 18 '16 at 22:57
2

Something more like this for a range..

RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^204\.246\.160\.([0-9]|1[0-9])
RewriteRule ^ http://www.domain.com%{REQUEST_URI} [L,R=301]

You can also use php, with something like this..

if ip = specific range
  redirect to site 1
else
 redirect to site 2

In response to your comment, use this..

COPY ALL OF THIS AS IS..

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^172\.56\.30\.223$
RewriteRule ^(.*)$ http://www.cat.com/$1 [L,R=301]
  • !=204\.246\.160\.([0-9]|1[0-9]) - Maybe a copy/paste error? But if you use the "lexicographically equal" operator (ie. = prefix) then the CondPattern becomes a literal string, not a regex. So, this would need to be something like !^204\.246\.160\.([0-9]|1[0-9]) – MrWhite Oct 1 '16 at 10:14
  • 1
    I think it's possibly not working on the single IP because it is pulling his proxy/router IP, but in regards to your comment, thank you as I did strip code above that was initially a range and did not change the aforementioned line. Thank you. – norcal johnny Oct 1 '16 at 10:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.