Reputation: 55
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
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
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