I have a two language site
Swedish side www.site.com
English side www.site.com/?lang=en
I'm using
RewriteEngine on
RewriteCond %{HTTP:Accept-Language} (aa|ab|af|am|ar|as|ay|az|ba|be|bg|bh|bi|bn|bo|br|ca|co|cs|cy|da|de|dz|el|en|eo|es|et|eu|fa|fi|fj|fo|fr|fy|ga|gd|gl|gn|gu|ha|hi|hr|hu|hy|ia|ie|ik|in|is|it|iw|ja|ji|jw|ka|kk|kl|km|kn|ko|ks|ku|ky|la|ln|lo|lt|lv|mg|mi|mk|ml|mn|mo|mr|ms|mt|my|na|ne|nl|no|oc|om|or|pa|pl|ps|pt|qu|rm|rn|ro|ru|rw|sa|sd|sg|sh|si|sk|sl|sm|sn|so|sq|sr|ss|st|su|sw|ta|te|tg|th|ti|tk|tl|tn|to|tr|ts|tt|tw|uk|ur|uz|vi|vo|wo|xh|yo|zh|zu) [NC]
RewriteRule .* www.site.com/?lang=en [L]
To get all languages but Swedish to the www.site.com/?lang=en
but I end up in a 310 loop.
what is missing ?
You need to add a check for
lang
to make sure you don't loop.Note that the
%1
is a backreference to the 2 letter language code that matched in the previous RewriteCond. The other thing about the Rule to note is that a request like/something/file.html
will get redirected tohttp://www.site.com/?lang=(2 letter language code)
. Essentially, the original path is lost. If you want to keep it, you need to match and use a backreference:If you want previous query strings to also get passed, for example,
/something/file.php?a=b
, you need to addQSA
in the brackets so that it will get redirected tohttp://www.site.com/somthing/file.php?lang=(2 letter language code)&a=b
.