Skip to content
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

SCRIPT_NAME and PHP_SELF are always vHost entrypoint even if using specific PHP file #62

Open
mglaman opened this issue Aug 27, 2024 · 2 comments

Comments

@mglaman
Copy link

mglaman commented Aug 27, 2024

I set up a file called baseurl.php to debug Symfony request object:

<?php

use Symfony\Component\HttpFoundation\Request;

$autoloader = require_once 'autoload.php';

$request = Request::createFromGlobals();
var_export([
  'SCRIPT_FILENAME' => $request->server->get('SCRIPT_FILENAME'),
  'SCRIPT_NAME' => $request->server->get('SCRIPT_NAME'),
  'PHP_SELF' => $request->server->get('PHP_SELF'),
  'filename' => basename($request->server->get('SCRIPT_FILENAME', '')),
  'scriptname' => basename($request->server->get('SCRIPT_NAME', '')),
]);
print PHP_EOL;
var_export($request->getUri());
print PHP_EOL;
var_export($request->getBaseUrl());
print PHP_EOL;
var_export($request->getBasePath());
print PHP_EOL;

The path is /cgi/drupal/baseurl.php

The output is

array (
  'SCRIPT_FILENAME' => '/persist/drupal/web//baseurl.php',
  'SCRIPT_NAME' => '/cgi/drupal/index.php',
  'PHP_SELF' => '/cgi/drupal/index.php',
  'filename' => 'baseurl.php',
  'scriptname' => 'index.php',
)

The script name is always overwritten when it shouldn't be.

		if(vHostEntrypoint)
		{
			scriptName = vHostPrefix + '/' + vHostEntrypoint;
		}

This should only happen if the path is rewritten to the docroot index.php. this worked only when going to a specific file

			// Rewrite to index
			path = docroot + '/index.php';
@mglaman
Copy link
Author

mglaman commented Aug 29, 2024

This hack seemed to fix it

		let originalPath = url.pathname;

		const extension = path.split('.').pop();

		if(vHostEntrypoint)
		{
			if (extension === 'php') {
				scriptName = vHostPrefix + '/' + rewrite.substr((vHostPrefix || this.prefix).length).replace(/^\/+/, '')
			} else {
				scriptName = vHostPrefix + '/' + vHostEntrypoint;
			}
		}

@seanmorris
Copy link
Owner

Hmm, that's annoying. Let me go over the code and I'll get a fix going.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants