0

I am facing a problem 500 server error, I try to redirect the user to a different URL depending on his country of origin using the .htaccess file and GEOIP, I use Codeigniter 3.

Error 500 : Is [Fri Jul 15 15:37:32.432374 2022] [core:error] [pid 3029:tid 140071902476032] [client 86.235.179.208:0] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

I would like to do this : https://example.com ----> https://example.com/fr/

Here's my script before adding the code :

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

and after adding the code :

    RewriteEngine On
    RewriteCond %{HTTP:X-FORWARDED-COUNTRY} ^France$
    RewriteRule ^([^/]+)$ /fr/ [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

Thanks in advance for your help.

8
  • So what is your actual problem? You stated your setup in a few words, but not what the actual issue is. You just mention some "server error" is the title and that something is "not working". But what does that actually mean? If that is a http status 500 (internal error), then please take a look into your http server's error log file. That is where you can simply read what the issue is. Commented Jul 15, 2022 at 8:16
  • It's an error 500 ( Is [Fri Jul 15 15:37:32.432374 2022] [core:error] [pid 3029:tid 140071902476032] [client 86.235.179.208:0] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace. ) Commented Jul 15, 2022 at 15:41
  • OK, so you have a redirection loop. Are you able to spot it? Commented Jul 15, 2022 at 16:19
  • Absolutely not, I have no idea where it can be located ? do you have a clue where I could look ? Commented Jul 15, 2022 at 16:46
  • I would expect that if you rewrite to say /fr/salut, that is then rewritten to /index.php?/fr/salut, which is again rewritten to /fr/index.php, what results in /index.php?/fr/index.php, which ... Commented Jul 15, 2022 at 16:52

1 Answer 1

0

The comments suggest that you are actually trying to redirect requests in a country specific manner. That is not what you implemented, though.

Take a look at this slightly modified variant:

RewriteEngine On

RewriteCond %{HTTP:X-FORWARDED-COUNTRY} ^France$
RewriteCond %{REQUEST_URI} !^/fr/
RewriteRule ^ /fr%{REQUEST_URI} [R=301,END]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.php?%{REQUEST_URI} [L]

The modifications should actually externally redirect requests without the /fr/ prefix if applicable. The rewriting loops is prevented because of the additional condition preventing the redirection if it already has been applied in a previous round trip. Not that I did not test this, I just sketched it here. You may have to adjust it to your specific setup.

Remember to always test using a fresh anonymous browser window. Also using a R=302 temporary redirection is a good idea and to only change that to a R=301 permanent redirection once your are satisfied. That prevents nasty caching issues on the client side.

You can implement such rules in the http server's host configuration. If you do not have access to that you can also use a distributed configuration file (".htaccess") which should be located in the DOCUMENT_ROOT folder of your http host.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.