Skip to content

Commit c0f7463

Browse files
committed
bug #16352 Fix the server variables in the router_*.php files (leofeyer)
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
2 parents f2e8722 + 4923411 commit c0f7463

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/router_dev.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
$_SERVER = array_merge($_SERVER, $_ENV);
3434
$_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'app_dev.php';
3535

36+
// Since we are rewriting to app_dev.php, adjust SCRIPT_NAME and PHP_SELF accordingly
37+
$_SERVER['SCRIPT_NAME'] = DIRECTORY_SEPARATOR.'app_dev.php';
38+
$_SERVER['PHP_SELF'] = DIRECTORY_SEPARATOR.'app_dev.php';
39+
3640
require 'app_dev.php';
3741

3842
error_log(sprintf('%s:%d [%d]: %s', $_SERVER['REMOTE_ADDR'], $_SERVER['REMOTE_PORT'], http_response_code(), $_SERVER['REQUEST_URI']), 4);

src/Symfony/Bundle/FrameworkBundle/Resources/config/router_prod.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
$_SERVER = array_merge($_SERVER, $_ENV);
3434
$_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'app.php';
3535

36+
// Since we are rewriting to app.php, adjust SCRIPT_NAME and PHP_SELF accordingly
37+
$_SERVER['SCRIPT_NAME'] = DIRECTORY_SEPARATOR.'app.php';
38+
$_SERVER['PHP_SELF'] = DIRECTORY_SEPARATOR.'app.php';
39+
3640
require 'app.php';
3741

3842
error_log(sprintf('%s:%d [%d]: %s', $_SERVER['REMOTE_ADDR'], $_SERVER['REMOTE_PORT'], http_response_code(), $_SERVER['REQUEST_URI']), 4);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy