title: apache2 mod_rewrite based on language then proxy
body: <p>I am trying to redirect a user that visits www.server.com to the browser's preferred language setting.</p>
  
  <p>When a user types in <code>www.server.com/&lt;lang&gt;</code>, /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.</p>
  
  <p>I have the following config:</p>
  
  <pre><code>&lt;VirtualHost *:8008&gt;
          ServerName www.server.com
          ServerAlias www
  
          ProxyPreserveHost On
  
          RewriteEngine On
  
          RewriteCond %{HTTP:Accept-Language} ^es [NC]
          RewriteRule ^/$ es/ [R=301,L]
  
        &lt;Proxy http://server.sl.smartling.com/*&gt;
            Allow from all
        &lt;/Proxy&gt;
  
        &lt;LocationMatch "/es"&gt;
            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"
        &lt;/LocationMatch&gt;
  
    DocumentRoot /www
    &lt;Directory /&gt; 
                  Options FollowSymLinks
                  AllowOverride None
          &lt;/Directory&gt;
          &lt;Directory /www/&gt;
                  Options Indexes FollowSymLinks MultiViews
                  AllowOverride all
                  Order allow,deny
                  allow from all
          &lt;/Directory&gt;
  
          ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
          &lt;Directory "/usr/lib/cgi-bin"&gt;
                  AllowOverride None
                  Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                  Order allow,deny
                  Allow from all
          &lt;/Directory&gt;
  
          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
  
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>I've tried stopping the loop with additional <code>RewriteCond</code> but can't seem to get it right. Any suggestions appreciated.</p>
  
  <p>Thanks</p>