Apache2 mod_rewrite based on language then proxy

I am trying to redirect a user who visits www.server.com to their preferred browser language.

When the user types in www.server.com/<lang>

/ es for Spanish in the example below, they are correctly proxied to smartling's broadcast servers. However, when the user sets their language preferences in their browser, they experience a redirect loop.

I have the following configuration:

<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

      <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"

  DocumentRoot /www
  <Directory /> 
                Options FollowSymLinks
                AllowOverride None
        <Directory /www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride all
                Order allow,deny
                allow from all

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all

        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



I tried to stop the loop with an extra RewriteCond

but didn't seem to figure it out. Any suggestions are appreciated.



source to share

1 answer

You need to add another condition to nullify the locale condition. The locale condition will always be true if set in the user's browser. Try adding a condition like this

RewriteCond %{REQUEST_URI} !^/es




All Articles