I am trying to redirect a user that visits www.server.com to the browser's preferred language setting.
When a user types in www.server.com/<lang>
, /es for spanish in the case below, they are correctly proxied to the smartling translation servers. However, when a user has their language preference set in their browser, they experience a redirect loop.
I have the following config:
<VirtualHost *:8008>
ServerName www.server.com
ServerAlias www
ProxyPreserveHost On
RewriteEngine On
RewriteCond %{HTTP:Accept-Language} ^es [NC]
RewriteRule ^/$ es/ [R=301,L]
<Proxy http://server.sl.smartling.com/*>
Allow from all
</Proxy>
<LocationMatch "/es">
ProxyPass http://server.sl.smartling.com/es
ProxyPassReverse http://server.sl.smartling.com/es
Header add Host "www.server.com"
RequestHeader set Host "www.server.com"
</LocationMatch>
DocumentRoot /www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/www-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/www-access.log combined
</VirtualHost>
I've tried stopping the loop with additional RewriteCond
but can't seem to get it right. Any suggestions appreciated.
Thanks
You'll need to add another condition to negate the locale condition. The locale condition will always be true if it is set in the user's browser. Try adding a condition like this
RewriteCond %{REQUEST_URI} !^/es
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With