apache2 mod_rewrite基于语言然后代理

das*_*vvv 5 apache mod-rewrite apache2 mod-proxy smartling

我正在尝试将访问www.server.com的用户重定向到浏览器的首选语言设置.

当用户在www.server.com/<lang>下面的情况下输入/ es为西班牙语时,它们被正确地代理到智能翻译服务器.但是,当用户在其浏览器中设置了语言首选项时,他们会遇到重定向循环.

我有以下配置:

<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>
Run Code Online (Sandbox Code Playgroud)

我试过用额外的停止循环,RewriteCond但似乎无法正确.任何建议赞赏.

谢谢

小智 4

您需要添加另一个条件来否定区域设置条件。如果在用户浏览器中设置了区域设置条件,则区域设置条件将始终为 true。尝试添加这样的条件

RewriteCond %{REQUEST_URI} !^/es
Run Code Online (Sandbox Code Playgroud)