在重写规则中反向引用 cookie 值

在重写规则中反向引用 cookie 值

我正在尝试反向引用 cookie 的值RewriteRule

# Trace rewrite rules log
LogLevel alert rewrite:trace4

# Rewriting the URL, in  the cookie's condition i've tried en alone, and en|fl|nl without sucess
RewriteCond %{REQUEST_URI} !redirect-lang
RewriteCond %{HTTP_COOKIE} !lang=(fr|en|nl)
RewriteRule ^(.*)$ /redirect-lang/%1$1 [R=301,L]
# Test if cookie exist then create it if not
SetEnvIf Cookie "lang=(.*)"  HAVE_locale=
Header set Set-Cookie "lang=fr; path=/;" env=!HAVE_locale 

预期的结果是:http://example.com/redirect-lang/nl/my/original/url但是我一直有http://example.com/redirect-lang//my/original/url(未检索到存储在 cookie 中的语言代码。我所做的反向引用不正确。

编辑:我删除了 cookies 并发送了请求http://example.com/testing/redirections/with/apache/mod/rewrite,以下是错误日志的输出:

    [....] init rewrite engine with requested uri /testing/redirections/with/apache/mod/rewrite
    [....] applying pattern '^(.*)$' to uri '/testing/redirections/with/apache/mod/rewrite'
    [....] pass through /testing/redirections/with/apache/mod/rewrite
    [....] init rewrite engine with requested uri /sites/all/themes/theme_name/img/burger.png, referer: http://front.example.com/testing/redirections/with/apache/mod/rewrite
    [....] applying pattern '^(.*)$' to uri '/sites/all/themes/theme_name/img/burger.png', referer: http://front.example.com/testing/redirections/with/apache/mod/rewrite
    [....] pass through /sites/all/themes/theme_name/img/burger.png, referer: http://front.example.com/testing/redirections/with/apache/mod/rewrite

任何帮助,将不胜感激。

相关内容