0

why is this causing a redirect loop? How do I have to change the code, to make it work?

RewriteEngine On
RewriteCond %{HTTP:Accept-Language} de [NC]
RewriteRule ^$ http://website.com/?___store=german
RewriteCond %{HTTP:Accept-Language} nl [NC]
RewriteRule ^$ http://website.com/?___store=dutch

Thank you,

Toby

asked Mar 11, 2012 at 11:44

2 Answers 2

1
RewriteEngine On
RewriteCond %{QUERY_STRING} !\b___store=\w+\b
RewriteCond %{HTTP:Accept-Language} de [NC]
RewriteRule ^$ /?___store=german [L,QSA]
RewriteCond %{QUERY_STRING} !\b___store=\w+\b
RewriteCond %{HTTP:Accept-Language} nl [NC]
RewriteRule ^$ /?___store=dutch [L,QSA]

You don't need the http://website.com. .htaccess files loop so adding [L] isn't good enough; you need to detect the loop and looking for the store parameter is a good way. You also need the [QSA] flag if some requests use additional params.

answered Mar 11, 2012 at 12:59
Sign up to request clarification or add additional context in comments.

3 Comments

Ok great, seems to work! Thanks a lot! :) I´m just not sure what happens if the visit is another language, which version does he get? Standard should be nl. Thanks.
I think there is still a bug in it, now it´s always the de-version loading. When I switch the preferred browser-language to NL, still the DE-version loads.
The Accept-Language header is a list. I don't know how yours is set up. Do a phpinfo() script and look for HTTP_ACCEPT_LANGUAGE; It may be that order is important. E.g. nl,de will give the symptoms that you suggest. You could try ^de and ^nl as the match strings, but this you fail on fr,de.
0

Try this:

RewriteEngine On
RewriteCond %{HTTP:Accept-Language} de [NC]
RewriteCond %{QUERY_STRING} !^___store [NC]
RewriteRule ^$ http://website.com/?___store=german [L]
RewriteCond %{HTTP:Accept-Language} nl [NC]
RewriteCond %{QUERY_STRING} !^___store [NC]
RewriteRule ^$ http://website.com/?___store=dutch [L]

If you go to website.com with AL of 'de', and then you get redirected to __store=german, your AL will still be 'de', so it will keep trying to redirect to that __store=german. Adding the [L] flag will stop apache from attempting to redirect multiple times.

This is another option, although the ___store parameter would have to be the same as the accept language. I think this should work (not exactly sure on the specifics of passing variables from a condition)

RewriteEngine On
RewriteCond %{HTTP:Accept-Language} (de|nl) [NC]
RewriteCond %{QUERY_STRING} !^___store [NC]
RewriteRule ^$ http://website.com/?___store=%1 [L]
answered Mar 11, 2012 at 12:03

3 Comments

Ok thank you, but it´s still not working. It´s still looping.
The request will still get redirected (because of the http://) and Accept-Langage gets matched again, which will redirect again, which will match again, etc., etc.
Interesting, I would have thought it would have stopped at that LAST rule, and not tried to rewrite it again. Updated my answer, though lol - totally didn't notice the other reply.. heh. wasnt there before o_o

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.