Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can a rule that filters and redirect traffic based on country of origin be implemented in .htaccess?

Can it be implemented in any other way then by an IP address? I need the solution to be as accurate as possible.

share|improve this question
I only know of using the .htaccess but that may require a large(ish) number of rules to cover all of the IP address ranges. What countries are you interested in? That may help someone to answer your question. Push comes to shove, I can perhaps see what IP address ranges exist for any country and create an example rewrite rule(s) that you can try. I expect there may be a better way though. I have no idea how people do this other than .htaccess. – closetnoc Apr 9 '14 at 3:12

Maybe this link (how to redirect domain according to country IP address) can help you.

I think, however, that this is not a good practice. Redirection by language or country is quite strict. It is better preferred:

  • A message at the top of your site that influence the visitor to go to the page built with his language.
  • A system that can easily change the language (flags)

This is only my opinion.

share|improve this answer

Yes, we used to filter visitors from Nigeria by .htaccess:

RewriteEngine On

RewriteRule ^(.*)$ http://www.google.com [L]

You can generate your own at http://ip2location.com/free/visitor-redirection .

share|improve this answer
You need an Apache module to use this htaccess: ip2location.com/developers/apache – dhaupin May 4 '15 at 13:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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