Skip to content

Fix the server variables in the router_*.php files #16352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Fix the server variables in the router_*.php files #16352

wants to merge 2 commits into from

Conversation

leofeyer
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets none
License MIT

The built-in web server automatically rewrites everything to the app_dev.php script, but it does not adjust the server variables accordingly.

Here is the output of print_r($_SERVER) on Apache with mod_rewrite enabled (relevant lines only):

Array
(
    [REQUEST_URI] => /text-elements.html
    [SCRIPT_NAME] => /app_dev.php
    [PHP_SELF] => /app_dev.php
)

And here is the output of the exact same script on the built-in server:

Array
(
    [REQUEST_URI] => /text-elements.html
    [SCRIPT_NAME] => /text-elements.html
    [PHP_SELF] => /text-elements.html
)

And here is the return value of Symfony's Request::getScriptName() method:

// Apache: http://localhost/text-elements.html
echo $this->container->get('request_stack')->getCurrentRequest()->getScriptName(); // /app_dev.php

// Built-in web server: http://127.0.0.1:8000/text-elements.html
echo $this->container->get('request_stack')->getCurrentRequest()->getScriptName(); // /text-elements.html

This PR fixes the two server variables in the router_dev.php script.

@fabpot
Copy link
Member

fabpot commented Oct 27, 2015

I think you also need to do the same changes in router_prod.php.

@bytehead
Copy link

I think you also need to do the same changes in router_prod.php.

Yes, the behaviour is also wrong in prod environment.

@leofeyer
Copy link
Contributor Author

You are right. I have updated the PR.

@TomasVotruba
Copy link
Contributor

What needs to be done here?

@xabbuh
Copy link
Member

xabbuh commented Nov 4, 2015

Isn't this something to be fixed in PHP?

@leofeyer
Copy link
Contributor Author

leofeyer commented Nov 5, 2015

Certainly not. Adjusting the environment variables is done by the rewrite module of your web server. Just look at the existing code:

https://github.com/symfony/symfony/blob/2.8/src/Symfony/Bundle/FrameworkBundle/Resources/config/router_prod.php#L34

$_SERVER['SCRIPT_FILENAME'] is already being adjusted; but since the script is in fact rewriting the URL, $_SERVER['SCRIPT_NAME'] and $_SERVER['PHP_SELF'] have to be adjusted accordingly, too.

@OskarStark
Copy link
Contributor

You should change (because of the prod file) the headline of this PR

@leofeyer leofeyer changed the title Fix the server variables in the router_dev.php file Fix the server variables in the router_*.php files Nov 12, 2015
@fabpot
Copy link
Member

fabpot commented Nov 13, 2015

Thank you @leofeyer.

fabpot added a commit that referenced this pull request Nov 13, 2015
This PR was squashed before being merged into the 2.3 branch (closes #16352).

Discussion
----------

Fix the server variables in the router_*.php files

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | none
| License       | MIT

The built-in web server automatically rewrites everything to the `app_dev.php` script, but it does not adjust the server variables accordingly.

Here is the output of `print_r($_SERVER)` on Apache with mod_rewrite enabled (relevant lines only):

```
Array
(
    [REQUEST_URI] => /text-elements.html
    [SCRIPT_NAME] => /app_dev.php
    [PHP_SELF] => /app_dev.php
)
```

And here is the output of the exact same script on the built-in server:

```
Array
(
    [REQUEST_URI] => /text-elements.html
    [SCRIPT_NAME] => /text-elements.html
    [PHP_SELF] => /text-elements.html
)
```

And here is the return value of Symfony's `Request::getScriptName()` method:

```php
// Apache: http://localhost/text-elements.html
echo $this->container->get('request_stack')->getCurrentRequest()->getScriptName(); // /app_dev.php

// Built-in web server: http://127.0.0.1:8000/text-elements.html
echo $this->container->get('request_stack')->getCurrentRequest()->getScriptName(); // /text-elements.html
```

This PR fixes the two server variables in the `router_dev.php` script.

Commits
-------

4923411 Fix the server variables in the router_*.php files
@fabpot fabpot closed this Nov 13, 2015
@OskarStark
Copy link
Contributor

👍

1 similar comment
@bytehead
Copy link

👍

This was referenced Nov 23, 2015
This was referenced Nov 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants