Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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
1  
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 at 3:12

2 Answers 2

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

RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^NG$
RewriteRule ^(.*)$ http://www.google.com [L]

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

share|improve this answer

Your Answer

 
discard

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.