5

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

Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
Mohammad Abu Musa
  • 1,117
  • 2
  • 10
  • 32

3 Answers3

2

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.

deceze
  • 510,633
  • 85
  • 743
  • 889
0
  1. mod_rewrite can't do geolocation, nor can it connect to an external service

  2. If your PHP code is doing the 301 redirect, then you'll need to preserve the query string in your PHP code. If you have an htaccess rule doing the 301 redirect, then the query string should be passed through with the redirect.

The documentation states:

Modifying the Query String

By default, the query string is passed through unchanged. [...] When you want to erase an existing query string, end the substitution string with just a question mark. To combine new and old query strings, use the [QSA] flag.
Jon
  • 12,684
  • 4
  • 31
  • 44
  • 1
    mod_rewrite by itself cannot, but mod_geoip (and others I presume) can, which enables you to do geolocation-based redirection directly with mod_rewrite. – deceze Jan 08 '14 at 12:22
0

In answer to question 1.

You can do the Geo IP direction in the vhost Apache configuration if you have mod_geoip/mod_geoip2 installed.

You can also do it using mod_rewrite if the mod_geoip/mod_geoip2 installed.

In answer to question 2.

You can use mod_rewrite to keep the existing query string on the rewritten url there are some examples of this here

Community
  • 1
  • 1
Nirav24x7
  • 16
  • 2