![]() |
geo redirect question
I'm looking for ideas for a geo redirect solution.
I want to be able to redirect traffic from ~200 domains to one domain. I want to do this not by country but by state. One of the server techs at my host has really gone above & beyond in his efforts to help me with this, but so far nothing has really been exactly what I need. As it stands, he's created a solution where a geo ip database and state blacklist reside on a shared folder on the server so that all domains can access it. This is important because I don't want to edit 200 separate domains every time I need to add or drop a state. His setup has every .php request being prepended with a call to go to a .php file that checks the user IP against the geo database and then either allows it to pass or redirects the request to a SFW domain. This is perfect for the .php files; but it's not the .php files that I need redirected, it's the image files .jpg .png etc. My only idea that would work with this setup is to .htaccess DENY FROM ALL the image folders then use the .php page to dynamically alter the .htaccess file and ALLOW FROM user ip's that did not trigger the redirect. This is far from ideal because it's going to cause the .htaccess files to grow quite large, requiring periodic purging of the ALLOW FROM ip's, which requires keeping track of when they were added so I can purge them every hour or whatever. it's also going to require me to edit ~200 .php files and even more image folders across all of my domains to set up this elaborate scheme. There must be a simpler way :helpme This seems like something better suited to a DNS level redirect rather than screwing around with each and every index.php and image folder on my system. PS - one more wrench in the works; my servers reside in a state that will be redirected, so they need to be able to exempt their own IP's so that they may communicate with one another. |
I would just redirect by country and then let surfer pick state. Those ip databases are not accurate for states on mobile devices. I used to show visitors location, now it's not worth it with the bots. Anyway it's simple with JavaScript and any premium IP location database API.
|
This can be achieved with .htaccess, Apache and Cloudflare
SetEnvIf CF-IPCountry (.+) GEO_COUNTRY=$1 RequestHeader set X-Debug-Country "%{GEO_COUNTRY}e" You will need mod_setenvif and mod_headers installed for Apache |
There's no reason you can't also use modrewrite to intercept image calls and run them through php as well.
It sounds like you're over complicating something basic. |
thanks for the replies!
|
If you're using MaxMind and Apache:
https://github.com/maxmind/mod_maxminddb If you're using MaxMind and Nginx: https://github.com/leev/ngx_http_geoip2_module |
also use the php c extension for max mind,its a lot faster.
quite a diff using maxmind for 100,000 lookups 45 seconds, with the maxmind c extension less than half a second |
thanks for the advice all, it is appreciated!
|
All times are GMT -7. The time now is 11:42 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123