0

I'm currently migrating a application from a very old symfony 2.1 version into a symfony 6 version.

And there is one piece of code that doesn't work anymore I cannot understand:

inside htaccess file there is multiple definitions like this one :

RewriteCond %{HTTP_HOST} ^www\.cg\.mywebsite(\.com)?(\:[0-9]+)?$
RewriteRule (.*) $1 [E=COUNTRY:57]

Which says that if the host patterns follows the rewrite cond, then I can get my country value equals to 57 in my PHP code

$country = $request->server->get('COUNTRY', 1);

This works just fine in the old application, but in the new one I always get 1, as if country was not defined at all

Old application: Symfony 2.1 / Php 5

New application: Syfony 6 / Php 8

7
  • just for kicks, can you verify that the result of getenv('COUNTRY), or dump($_SERVER)` and see if COUNTRY is there? Commented Dec 23, 2021 at 12:16
  • Depending on the structure of your .htaccess file the environment variable could be getting renamed to REDIRECT_COUNTRY before your application receives the request (and COUNTRY is not being re-set). You should also be setting this like RewriteRule ^ - [E=COUNTRY:57] - and this could even resolve the issue in some cases (because there is no substitution the rewrite engine does not start over). Commented Dec 23, 2021 at 12:47
  • And it's also possible that the environment variables set by Apache are not transmitted to your CGI handler. Dumping $_SERVER, $_ENV (or having a look at phpinfo()) can hopefully shred light on that. Commented Dec 23, 2021 at 14:33
  • 1
    getenv('COUNTRY') results nothing, looked into $_SERVER and COUNTRY is not inside. Also checked for REDIRECT_COUNTRY and nohthing. Changed the rewrite rule as you advised and still nothing. Looked into $_SERVER and $_ENV and found no "COUNTRY" inside Looked into phpinfo and i can read cgi.redirect_status_env with "no value". Could it be what you mentioned as "environement variables not transmited to cgi ?" Also note that I'm doing all this tests in local server from a windows PC Commented Dec 23, 2021 at 14:47
  • 3
    "I'm using is the built in local symfony server" - .htaccess is an Apache config file. If you are using the local "built-in" web server then your .htaccess file is not processed (so the env var will not be set). stackoverflow.com/questions/53759815/… Commented Dec 23, 2021 at 15:20

1 Answer 1

1

the local server I'm using is the built in local symfony server.

.htaccess is an Apache config file. If you are using the built-in symfony web server (or the PHP built-in web server) then this is not Apache and the .htaccess file is not going to be processed (and the env vars are not going to be set).

If you need the .htaccess file to be processed for your application logic then you'll need to run Apache, or move this logic to your application/PHP.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.