Adding Multiple Conditions to SetEnvIf

I need to use SetEnvIf in my .htaccess file.

I also need to fulfill several conditions, and then show the required URL.

Here is my code:

 SetEnvIf Remote_Host "^" press_flag=0 SetEnvIf Request_URI '/press/$' press_flag=1 SetEnvIf Cookie 'language\_uiAAAenglishBBB' press_flag=press_flag+1 SetEnvIf press_flag 2 Request_URI='Remote_Host/eng/test.html' 

Explanation:

  • In the first line, I set the press_flag variable to 0 .
  • The second line, I check if the URL ends with this text: /press/ , if true, I set 'press_flag' to 1 .
  • The third line, I check if the cookie language\_uiAAAenglishBBB text, if true, then I increase the value of press_flag by 1.
  • The last line, I check if the press_flag value is 2, then I set HTTP_HOST accordingly.

But when I open the URL/press/ in the browser, it is not redirected.

Please help debug and fix this code.

Thanks.

+6
source share
1 answer

I do not think you can redirect using SetEnvIf . Instead, use mod_rewrite :

 RewriteCond %{REQUEST_URI} =/press/ RewriteCond %{HTTP_COOKIE} \blanguage=english\b RewriteRule .* /eng/test.html [R] 
  • Checks if requested / press /.
  • Checks whether a cookie is set to a specific value.
  • Redirection rule
+1
source

Source: https://habr.com/ru/post/948465/


All Articles