We have a php-based website and want to set an env variable based on host and the first part of the request uri. The site is running apache with mod_rewrite and fpm.
I found SetEnvIfExpr and tried to add this to the .htaccess:
SetEnvIfExpr "%{HTTP_HOST} =~ m#.*example.com.*# && %{REQUEST_URI} =~ m#^/de.*#" RUN_CODE=german
I want to match all urls starting with example.com/de.
Doing a var_dump($_SERVER['RUN_CODE']); in my index.php gives me NULL.
Through trial and error I figured out the following:
- When I modify the last request (the one matching
REQUEST_URI) to^.*de.*it works correctly. Sadly, that's not really a solution because this could match other urls not starting with/de. - I suspected this issue comes from the processing order of
mod_setenvifandmod_rewrite.var_dump($_SERVER['REQUEST_URI']);gives me only/de/...but I found that modifying the regex to^/in.*de.*matches.^/index.php/de.*does not.