i have a survey community with 3 languages using the WPML plugin for Wordpress to handle the languages. unfortunately the language detection works only via php. i want to use htaccess, since it is faster and the user wouldn't notice a delay.
The setup is the following:
community.netigate.net/ (English, International)
community.netigate.net/de/ (German)
community.netigate.net/sv/ (Swedish)
i tried different approaches and found the best one to be the one at
Since most users are Germans or Swedes, I want "English" only to be the standard fallback language. the setup could be like this:
CHECK IF Language is Swedish, THEN redirect to swedish subpage
CHECK IF language is German, THEN redirect to German subpage
ELSE use English as Fallback
Unfortunately the solution below ends up in endless redirects? Did I miss something?
## Language Detection
#The 'Accept-Language' header starts with 'sv'
#and the test is case-insensitive ([NC])
RewriteCond %{HTTP:Accept-Language} ^sv [NC]
#Redirect user to /sv/hauptseite address
#sending 301 (Moved Permanently) HTTP status code
RewriteRule ^$ /sv/ [L,R=301]
#The 'Accept-Language' header starts with 'de'
#and the test is case-insensitive ([NC])
RewriteCond %{HTTP:Accept-Language} ^de [NC]
#Redirect user to /de/hauptseite address
#sending 301 (Moved Permanently) HTTP status code
RewriteRule ^$ /de/ [L,R=301]
#For every other language (including English :)) use English
RewriteRule ^$ / [L,R=301]
Add another rewrite condition that checks if redirection has already taken place
## Language Detection
#The 'Accept-Language' header starts with 'sv'
#and the test is case-insensitive ([NC])
RewriteCond %{HTTP:Accept-Language} ^sv [NC]
#If not already redirected
RewriteCond %{REQUEST_URI} !^/sv/ [NC] # ADDED
#Redirect user to /sv/hauptseite address
#sending 301 (Moved Permanently) HTTP status code
RewriteRule ^$ /sv/ [L,R=301]
#The 'Accept-Language' header starts with 'de'
#and the test is case-insensitive ([NC])
RewriteCond %{HTTP:Accept-Language} ^de [NC]
#If not already redirected
RewriteCond %{REQUEST_URI} !^/de/ [NC] # ADDED
#Redirect user to /de/hauptseite address
#sending 301 (Moved Permanently) HTTP status code
RewriteRule ^$ /de/ [L,R=301]
#For every other language (including English :)) use English
RewriteRule ^$ - [L] # MODIFIED