重定向到基于 cookie 的语言环境

Redirect to a locale based on cookie

我们的网站使用自定义语言环境。我们将用户选择的语言环境保存在 cookie 中。我将如何添加到我的 htaccess 文件以完成重定向到基于 cookie 的正确语言环境?我们的语言环境最终在 /dallas, /fort-worth , /plano 到 url 之前。

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule (.+) index.php?p= [QSA,L]
</IfModule>

假设您设置 cookie locale=value 然后写.htaccess

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_COOKIE} locale=([^;]+) [NC]
RewriteRule ^(.*)$ /%1/index.php?p= [NC,L,QSA]

即www.examle.com/smtng.html => www.examle.com/value/index.php?p=smtng.html