Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Re-directing country-specific traffic.


Guest

Recommended Posts

Posted

How can one re-direct all traffic from a certain country to a specific url?

 

I know how to block traffic from a country but not re-direct it.

 

For example I've seen CPA offers doing this and I want to do it on a site as well.

Posted

It should be very similar to blocking traffic. First, I take it that you want to redirect visitors coming from specific countries to a specific site or sub-site? The information that would be available would be their IP addresses. There are services (both free and commercial) that claim to be able to map IP address ranges to a given country. I don't know how accurate they are, but it's a start (I would assume that's what you use to block by country). Then, in either your .htaccess file (similar to IP blocking) or in a PHP script, you either redirect then and there, or do something else depending on the country. What you might consider doing is adding a URL query string like country=FR, and modifying the osC code to pay attention to that new setting, if present. If you redirect visitors to different (sub-)sites based on IP address, give them a means to override this and go to a specific country of their choice. Never force them into a particular (sub-)site based on IP address -- they may have legitimate reasons to visit another country's store (e.g., they're going on holiday there, or the IP mapping may be incorrect, or they prefer the language). Speaking of language, the browser tells osC what language it is configured to use, so you may wish to (allow) override of that behavior. Lots of things to do, and to watch out for! It depends in part on what you're trying to do here... restrict users in some way (say, certain offers only good in certain countries), or make the shopping experience more enjoyable by using their language and offering country-appropriate products.

Posted

What I want to do is redirect all traffic from a specific country to an opt-in page.

 

I can get all the IP's from here - http://www.blockacountry.com/

 

But I don't know how to implement the redirecting part into .htaccess

 

Thanks.

  • 1 month later...
Posted

Any help from someone please? Thanks.

Posted

Sorry, been away all week.

 

OK, so you can get a list similar to

order allow,deny
deny from 41.200.0.0/15
deny from 41.209.128.0/18
deny from 41.210.64.0/18
deny from 41.220.144.0/20
...

which would go into your .htaccess file to block those IP addresses. But instead of blocking them, you want to redirect to a specific page? I think that might be more easily handled in a PHP script than with the voodoo of .htaccess. You might want to read http://httpd.apache.org/docs/1.3/mod/mod_access.html to get details.

RewriteCond %{REMOTE_ADDR} 41.200.* [OR]
RewriteCond %{REMOTE_ADDR}  41.209.* [OR]   ...etc...
RewriteRule .* /opt_in_page.php [L]

(adapted from http://perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/).

 

Now, do you want to send a given user to the opt-in page just once per visit, or just once, period? Somewhere you need to keep track of whether this visitor has already visited the special page (by session, by cookie, by ID) and not send them to the page. That might be easier to do in PHP, looking at $_SERVER['REMOTE_ADDR'] (I think that's the one that has the IP address). Call some new Check_Country.php script from application_top.php, and have it go first to the opt-in page (if the user hasn't been there yet) and then return a flag that they refused to opt-in (kick them out of your store) or they either opted-in, or opted-in in a previous trip through application_top.php. Then application_top.php keeps going as usual. Something like that.

 

Keep in mind that blocking/rerouting by IP address is not foolproof. IP addresses may not correspond neatly to a country, or may be spoofed, or may be coming through a proxy, or may otherwise not match up. Use this feature only to improve customer experience, not to block or otherwise be perceived as harassing them -- you're likely to tick off more legitimate customers than block/catch bad ones.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...