Lets assume my website is mywebsite.com. I need to block the website for all the countries except India. But we need to handle the block gracefully, i.e. showing a page that right now the site is not providing services in their country.

Page on my website visible in India: mywebsite.com/category.php

When someone outside India opens the website they should see the following URLs: mywebsite.com/world/category.php

Kindly note that Google Search should always show the URLs without "world" in there.

Following are the solutions I have on mind:

Scenario: Someone tries to open mywebsite.com/category.php from US. The code will check for the IP location and the user would be redirected to mywebsite.com/world/category.php

Solution1: Add no follow and no index tags on mywebsite.com/world/category.php so that Google does not index this page and use a 302 redirection. This page will be served to everyone from outside India.

Solution2: Add a 302 redirect from mywebsite.com/category.php to mywebsite.com/world/category.php and also add canonical on mywebsite.com/world/category.php as website.com/category.php

Problem in this approach is loop for Google bot, first we are doing a redirect and then we are putting a canonical to the one which as redirected. Sounds wrong to me but I am not sure.

Note: This question is related SEO strategy. I want your suggestions on my SEO strategy. I do not want any technical solution for redirection from .htaccess or IP blocking outside India traffic .

2 Answers 2


Filter visitors by .htaccess:

RewriteEngine On

RewriteRule ^(.*)$ http://Mywebsite/Indiapage.php [L]

And for the rest you redirect to world/worldpage

  • That looks like it requires something else to make it work. Maybe the IP2Location Apache module? ip2location.com/developers/apache Oct 24, 2016 at 18:40
  • That is correct it's enabled by default on my servers so I tend to forget that not everyone has it. Well the idea stays the same he should allow IPs from India and redirect anything else to /world Oct 24, 2016 at 18:43
  • Thank you for reply, I do not want any technical answer for .htaccess redirection or IP blocking. I want to know whether my strategy is correct or not from SEO point of view.. Oct 25, 2016 at 8:59

Here is the ip range for India http://www.nirsoft.net/countryip/in.html

use above address and codes below (you need to enter ip ranges by yourself)

$deny = array("1.6.0", "1.22.0", "223.224.0");
if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) {
header("location: http://mywebsite.com/world/category.php");
} ?>

or this

if(strpos($_SERVER['REMOTE_ADDR'], "14.102") === 0))

you need to do some work but this is the way that I can think of. You can try use wildcard for php (*) for the similar ip ranges

  • 1
    Please don't do this with php. If you're going for this method, use htaccess with a redirect. Much MUCH faster end resource friendly.
    – Martijn
    Oct 24, 2016 at 12:55
  • That PHP code won't work, either, as it is technically incorrect.
    – John Conde
    Oct 24, 2016 at 13:45
  • Thank you for reply, I do not want any technical answer for .htaccess redirection or IP blocking. I want to know whether my strategy is correct or not from SEO point of view.. I have updated my question kindly review. Oct 25, 2016 at 9:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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