0

I'm trying to backreference a cookie's value in a 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 

The result expected is : http://example.com/redirect-lang/nl/my/original/url but I keep having http://example.com/redirect-lang//my/original/url (The language code stored in the cookie isn't retrieved.backreference I made isn't correct.

Edit: I deleted the cookies and send a request to http://example.com/testing/redirections/with/apache/mod/rewrite and here is the ouput of the error log:

    [....] 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

Any help would be appreciated.

  • Please turn on rewrite logging to see what actually happens, and then include the relevant log lines in your question. (Apart from that, it's a good and well-written question and for once I don't think our standard mod_rewrite canonical question answers it.) – Jenny D Jan 14 '16 at 17:05
  • The logs (error log) doesn't return any issue. And thank you @JennyD for your comment. That is surely encouraging for a beginner (like me ^^) – Ismail H Jan 14 '16 at 20:10
  • You need to turn on some extra logging. Have a look at httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritelog for info on how to turn it on; you need both RewriteLog and to set RewriteLogLevel to at least 3. – Jenny D Jan 14 '16 at 20:14
  • thank you so much for the tip. I've been debugging today and I see better the problem. I'll update the question as soon as I can put it in (understandable) words. – Ismail H Jan 18 '16 at 9:55
  • I edited the question to add the logs. – Ismail H Jan 18 '16 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.