I am wondering how Kirby determines the domain name the site is running on. I have one site where the config.php always gets used despite a specific config for the domain existing.
The only thing different with this particular site is that there is a .htaccess rule that forces the www at the start of the URL. Could this be interfering?
The config file name is in the form of config.domainname.com.php. Do I really need to put the www in the file name?
Hm, the examples don’t have a www subdomain, but /site/config/config.staging.yourdomain.com.php. Were you assuming that www is another sort of subdomain than staging? But I can of course add it as another example.
Well, while it is pretty unlikely that http://www.example.com and http://example.com are used for different purposes, from a technical point of view that would be possible. So it would be rather un-Kirby-ish to assume both are the same.
@flokosiol If that was the case, the domain specific config file would be loaded instead of the subdomain specific www file? I can’t see where this would remove the www from the SERVER_NAME?
Strange … I double checked this on a live site and the www gets removed when I var_dump the $configs … but locally it’s like you said!? Everything as expected …
@flokosiol I just tested this on a remote domain, just to make sure, with the same result as above.
And, as I wrote above, the preg_replace() function doesn’t remove the www bit, all it does is remove all characters that are not a word character (alphanumerical characters plus underscore including unicode characters), not a colon, not a dot, and not a dash. Since www doesn’t fall into any of these categories, it is not removed, as you can see from the example I posted above.
I don’t know what is happening on your site, but there’s nothing in the code to confirm your theory, I’m afraid?
I follow @texnixe, she is correct here as always !
@jimbobrjames:
But your problem is, I think, outside of Kirby:
Put the following code temporarily (security !!!) in a template or snippet and call a page using that code:
<?php phpinfo(); ?>
In that page search for “SERVER_NAME” in the first column of a table.
And view that page by changing between your websites "www.example.com" and “example.com”.
Does the content in the second column change?
I guess no. Then this is your problem, which you may want to resolve. Look at your webservers configuration…
If you use the www.example.com domain, name your domain specific config config.www.example.com.php
If you use the example.com domain, name your domain specific config config.example.com.php.
If you reroute from non-www to www, you use the www domain, not the non-www domain.
@anon77445132 you won’t even see the phpinfo for the non-www domain because the rerouting takes place before PHP kicks in (unless you remove the redirect from the .htaccess but that changes everything, anyway).
Sorry to dig this one up again, but i’ve run into it again, on a different server. It only loads config.php, not the domain specific config.
If i put this in a comment tag in my site head:
<?php echo server::get(); ?>
The result is:
<!-- Array -->
Gives me nothing. How can it be that Kirby can’t figure out what the domain is, in order to load the config? Is there something else I can try to figure out whats going on?
Edit: Ah. It’s an array. Should have done…
<!-- <?php var_dump(server::get()); ?> -->
The info it gives me tells me the config is named correctly. The domain name has a hyphen in the middle of it. Would that be a problem?