Skip to content

Commit b65b1f5

Browse files
Revert "fix: fixed the codeigniter routing for installations in subdirectories with the page index."
This reverts commit 1bb8f52.
1 parent 1bb8f52 commit b65b1f5

1 file changed

Lines changed: 4 additions & 38 deletions

File tree

system/HTTP/SiteURIFactory.php

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -111,43 +111,9 @@ public function detectRoutePath(string $protocol = ''): string
111111
*/
112112
private function parseRequestURI(): string
113113
{
114-
$serverScriptName = $this->superglobals->server('SCRIPT_NAME'); // This is the SCRIPT_NAME, it's a variable that contains the name of the script being executed, it's used from the codeigniter framework to perform the routing process.
115-
// We need to check if the project is in a subdirectory
116-
$projectIsInSubDir = false; // Variable used to check if the project is in a subdirectory
117-
$baseURLConfig = config(\Config\App::class)->baseURL; // Base URL configuration from the Config\App class or .env file
118-
$baseUrlParsed = parse_url($baseURLConfig); // PHP function to parse the URL
119-
$baseUrlPath = ""; // If the url does not have a / at the end like https://example.com the path will not be set by parse_url
120-
if(isset($baseUrlParsed['path'])) { // Check if the path is set in the parsed URL (read the line above)
121-
$baseUrlPath = $baseUrlParsed['path'] ?? "";
122-
}
123-
124-
// We need to check that the project is in a subdirectory, if it is in a subdirectory we need to remove the public directory from the script name
125-
$baseUrlPathArr = explode('/', $baseUrlPath);
126-
foreach($baseUrlPathArr as $i => $pathFragment){
127-
if($pathFragment === "") unset($baseUrlPathArr[$i]);
128-
}
129-
if(count($baseUrlPathArr) > 0){ // Check that the path has at least one fragment
130-
$projectIsInSubDir = true; // The project is running in a subdirectory
131-
}
132-
133-
// We need to remove public from the script name, this way we can correctly perform the routing
134-
if($projectIsInSubDir){
135-
$subDirPath = "/" . implode("/", $baseUrlPathArr); // This is the path of the subdirectory, we are using arrays because it can be multiple levels deep
136-
$subDirPathPosition = strpos($serverScriptName, $subDirPath."/public"); // This is the position of the public directory in the script name. The strpos function returns only the first instance
137-
if ($subDirPathPosition !== false) { // We are checking if the public directory is found in the script name.
138-
$serverScriptName = substr_replace(
139-
$serverScriptName, // The input string.
140-
$subDirPath, // The replacement string.
141-
$subDirPathPosition, // The offset from where we are replacing.
142-
strlen($subDirPath."/public") // The length of the portion of string which is to be replaced.
143-
);
144-
}
145-
}
146-
147-
148114
if (
149115
$this->superglobals->server('REQUEST_URI') === null
150-
|| $serverScriptName === null
116+
|| $this->superglobals->server('SCRIPT_NAME') === null
151117
) {
152118
return '';
153119
}
@@ -162,13 +128,13 @@ private function parseRequestURI(): string
162128

163129
// Strip the SCRIPT_NAME path from the URI
164130
if (
165-
$path !== '' && $serverScriptName !== ''
166-
&& pathinfo($serverScriptName, PATHINFO_EXTENSION) === 'php'
131+
$path !== '' && $this->superglobals->server('SCRIPT_NAME') !== ''
132+
&& pathinfo($this->superglobals->server('SCRIPT_NAME'), PATHINFO_EXTENSION) === 'php'
167133
) {
168134
// Compare each segment, dropping them until there is no match
169135
$segments = $keep = explode('/', $path);
170136

171-
foreach (explode('/', $serverScriptName) as $i => $segment) {
137+
foreach (explode('/', $this->superglobals->server('SCRIPT_NAME')) as $i => $segment) {
172138
// If these segments are not the same then we're done
173139
if (! isset($segments[$i]) || $segment !== $segments[$i]) {
174140
break;

0 commit comments

Comments
 (0)