texnixe:
And since I can’t re-create your setup, I can’t test why it doesn’t work.
If anyone cares to try this and runs Apache, create/edit a VirtualHost
section and add both ServerName
and ServerAlias
using different names.
Also add both host names to the hosts file of your developer machine.
<VirtualHost 127.0.0.1:80 192.168.178.26:80 10.0.0.26:80> # check IP
ServerName dev.fritz.box # autogenerated by Fritz!Box [1]
ServerAlias local.kunde.de
DocumentRoot ...
</VirtualHost>
This setup presumes you do all developemt in your LAN. If you deploy your tests to a public webserver none of this applies to you. Also: none of this will trouble you or makes sense if you have the ability to edit your router’s DNS or use some other network trickery. In which case you’re also unlikely to run into the “mixed hostname” problem in the first place.
The Tests
Make sure the site template makes calls to css()/js()
or content contains (image:)
.
Somewhere in your template add:
<pre>
SN: <?= $_SERVER['SERVER_NAME'] ?>
HH: <?= $_SERVER['HTTP_HOST'] ?></pre>
Open your website using the ServerName dev.fritz.box
.
Things should look fine. Check from the computer running the webserver and some other device in your W/LAN. Both SERVER_NAME and HTTP_HOST refer to the same hostname.
Now open the website using the ServerAlias local.kunde.de
instead.
Your site should look broken: no CSS applied, JS not running, images missing. Check the generated HTML in your DevTools or viewsource.
Note that CSS and JS links and IMG tags still contain the dev.fritz.box
hostname.
This time SERVER_NAME is still dev.fritz.box
but HTTP_HOST became: local.kunde.de
. The name actually entered into the browser.
Why does all of this matter?
Other than toying with debugging a Kirby site running in Firefox or Chrome on a USB tethered device? Well, if the computer running the webserver is only known by a single name (it’s own hostname) inside the LAN you can’t run/test multiple sites/domains running on that very machine using other devices in your network. The webserver will always respond serving the first/single VirtualHost that matches it’s own hostname and LAN-IP.
That’s of course not a show-stopper for many, but utterly inconvenient if you work on multiple projects simultaniously or a multi-domain project running different backend systems (shop, blog, website, forum).
Also you can’t mimic a “CDN” properly and using DynDNS will probably fail, too.
Then there are circumstances “in the wild” where a (physical) server has different hostnames within its LAN, sitting behind a proxy or firewall. In this case the (public) HTTP_HOST and (local) SERVER_NAME don’t match. As a result any URL generated using the SERVER_NAME only will no longer point to a ressource accessible to the public eye (also a DynDNS scenario).
[1] If you have a Fritz!Box router, every device’s local hostname in your W/LAN will automatically become part of the local .fritz.box
domain, i.e “dev.fritz.box”, ". That’s also the ServerName
you have to use in order access your local webserver from all devices in yoru LAN.
Cheers.