Description
PHP Version
8.2
CodeIgniter4 Version
4.4.3
CodeIgniter4 Installation Method
Composer (as dependency to an existing project)
Which operating systems have you tested for this bug?
Windows
Which server did you use?
apache
Database
MariaDB 10
What happened?
I have a site with a wildcard subdomain, where I use for the subdomains for localization. I was having difficulties getting the subdomains to work as they don't match the base_url. I saw a post suggesting using an option in the routing to allow any domain to match ['subdomain => '*']
.
If you try to set the option ['subdomain => '*']
on a route, it works for all subdomains except www. There it generates an error saying it could not find a route for the path.
I looked into the code and found the following at line 1649 in RouteCollection.php
if ($host[0] === 'www') {
unset($host[0]);
}
This explicitly sets a special case for www and removes it as the subdomain and I can't see why!
If I comment these lines out it works as I would expect.
I assume that this code was added for some use-case where there is an extra www in front of the 'proper' subdomain.
However, since www may be the actual subdomain, this is a bug. ['subdomain => '*']
should match ANY subdomain, not any subdomain except www.
Steps to Reproduce
Setup a route as follows:
$routes->get ('/', 'PublicPages::index', ['subdomain' => '*'] );
try accessing the page as
https://sub.mydomain.com/ - loads the correct page
try accessing the page as
https://www.mydomain.com/ - 404 Can't find a route for 'get: /'.
Expected Output
Normal page loading, not a 404 Can't find a route for 'get: /'.
Anything else?
No response