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
2 Answers 2
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.
3 Comments
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.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]
3 Comments
http://) and Accept-Langage gets matched again, which will redirect again, which will match again, etc., etc.