Stealthbird97
Stealthbird97

Reputation: 55

Mod_rewrite Redirect Specific IP to page

I've been trying to get my website to redirect a specific IP to a particular page.

Using the Following in my .htaccess file

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} ^138\.91\.49\.132$
RewriteRule .* http://www.anothersite.com/mypage.html [R=302,L]

The IP 138.91.49.132 should be redirected. Nothing gets redirected.

When I use this

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^138\.91\.49\.132$
RewriteRule .* http://www.anothersite.com/mypage.html [R=302,L]

Everything except 138.91.49.132 should be redirected. Everything gets redirected.

What exactly is going on here as it is getting me very frustrated... am I doing something wrong?

Upvotes: 1

Views: 526

Answers (2)

Stealthbird97
Stealthbird97

Reputation: 55

I managed to get it working by using the HTTP:CF-CONNECTING-IP as it seems Cloudflare CDN was disrupting the use of RewriteCond %{REMOTE_ADDR}

RewriteCond %{HTTP:CF-CONNECTING-IP} ^(212\.219\.11\.6)$
RewriteRule (.*) http://lol.awebsite.co.uk [R=301,L]

Thank you anubhava for getting me to this stage.

Upvotes: 3

anubhava
anubhava

Reputation: 785266

You need to use REMOTE_ADDR instead:

RewriteEngine On

RewriteCond %{REMOTE_ADDR} ^138\.91\.49\.132$
RewriteRule (.*) http://www.anothersite.com/mypage.html [R=301,L]

Upvotes: 0

Related Questions