apache2 mod_rewrite基于语言然后代理

时间:2015-04-21 22:20:18

标签: 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>

我已经尝试使用额外的RewriteCond停止循环,但似乎无法做到正确。任何建议表示赞赏。

由于

1 个答案:

答案 0 :(得分:4)

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

RewriteCond %{REQUEST_URI} !^/es