Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IP Geo location with Mod_Rewrite & PHP

I am writing a small script in which it redirects to country specific landing pages(example: if you come from Germany you will be re-directed to xyz.com/de/) this redirection happens using index.php which connects to web service returns the country the user is accessing the website from then I redirect the user using 301 to a the new page xyz.com/de/

I have two questions

1- Can the same functionality integrated with mod_rewrite, if so what is the advantage in terms of performance and SEO quality?

2- Can the mod_rewrite save the query string including GCLID on the redirects (as I am concatenating the $_SERVER to php redirection

like image 236
Mohammad Abu Musa Avatar asked Nov 02 '22 07:11

Mohammad Abu Musa


1 Answers

You can install mod_geoip on your server, which enables database-based geolocation lookup directly inside Apache. Look at the examples for exactly the scenario you talk about.

The advantage would be much better performance, since the lookup will be done locally using a database, instead of needing to call an external web service. It also requires virtually no code once this is set up, easing maintenance. You will only have to make sure your local copy of the lookup database is regularly updated, typically with a weekly/daily cron job.

You can rewrite the URL in any way you want appending any parameters you want.

SEO-wise it should have no effect at all compared to PHP based redirects, since to the client the behaviour appears exactly the same.

like image 93
deceze Avatar answered Nov 09 '22 13:11

deceze