#106143site:config languages baseVariants condition `getenv` matches
Description
given two domains (incl. `www`)
- domain.de
- www.domain.de
- domain.com
- www.domain.com
languages:
-
title: Deutsch
enabled: true
languageId: 0
base: /de/
baseVariants:
-
base: 'https://domain.de/'
condition: 'applicationContext == "Production" && getenv("HTTP_HOST") matches "/de$/"'
[..]
-
title: English
enabled: true
languageId: 1
base: /en/
baseVariants:
-
base: 'https://domain.com/'
condition: 'applicationContext == "Production" && getenv("HTTP_HOST") matches "/com$/"'
the `regex` seems not to work – any ideas?
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
History 13
-
Marcus Förster changed description 02/10/25, 15:35
-
Garvin Hicking commented and changed status
NewNeeds Feedback 02/10/25, 17:10 -
Marcus Förster commented 02/10/25, 17:51
yes ; it returns the called host with HTTP_HOST (in comp. to SERVER_NAME which is the `apache` def.)
cat > public/test.php << EOL <?php echo getenv('HTTP_HOST');flush(); EOL -
Garvin Hicking commented 02/10/25, 19:23
Am “on the run” but a quick idea, did you try:
condition: 'applicationContext == "Production" && getenv("HTTP_HOST") matches "#de$#"'the examples always use
#as a delimiter, that might be enforced for the regexp….? -
Marcus Förster commented 02/10/25, 19:48
yea (tested) but regex does not care if / or #; first char will be last char (or error)
-
Marcus Förster commented 02/10/25, 19:58
fyi/ switched the order @ languages: => `Resover` will pick the first entry BUT still “Reason: No site configuration found“
might be additional something “deeper” that even if found the domain is checked somewhere else again and error thrown ..condition: 'getenv("HTTP_HOST") == "www.domain.com"' -
Marcus Förster commented 02/10/25, 20:05
btw/applicationContext == "Production" && getenv("HTTP_HOST") ends with ".com"also does not work -
Garvin Hicking commented 02/10/25, 20:07
Oh I just saw, you report this for TYPO3v11 which is out of support. Did you by chance try this with v12+?
I just set it up with my TYPO3 v12 and it works:
base: '/' baseVariants: - base: 'https://build.demo.ddev.site/' condition: 'getenv("HTTP_HOST") == "build.demo.ddev.site"' - base: 'https://demo.ddev.site/' condition: 'getenv("HTTP_HOST") matches "#ddev.site$#" && getenv("HTTP_HOST") matches "#demo#"' - base: 'https://demo.domain.org' condition: 'applicationContext == "Production/Staging"' - base: 'https://www.domain.org' condition: 'applicationContext == "Production/Production"'Maybe you can dig deeper and create a minimum “broken” configuration. Try with a fresh vanilla installation with just the bare, minimal site config and work from there…?
-
Marcus Förster commented 02/10/25, 20:33
will upgrd. to 12 these days and check – thanks for your time and testing efford
may you try .. & check if https://demo.domain.org outputs www.domain.org- base: 'https://demo.domain.org' - condition: 'applicationContext == "Production/Staging"' - - base: 'https://www.domain.org' - condition: 'applicationContext == "Production/Production"' + condition: 'applicationContext == "Production/Production" && getenv("HTTP_HOST") matches "#\.org$#"' -
Garvin Hicking commented 02/10/25, 21:19
Aaaah, now I think I understand what you try to do, you want to setup wildcard matching with a condition but only have one basevariant entry.
I must admit I’m not deep into the technical side of things, but in the projects I’ve been involved in, all possible URLs/domauins would need to be specifically listed with an exact matchin `base` entry.
So in your case:
title: Deutsch enabled: true languageId: 0 base: /de/ baseVariants: - base: 'https://domain.de/' condition: 'applicationContext == "Production" && getenv("HTTP_HOST") == "domain.de"' - base: 'https://www.domain.de/' condition: 'applicationContext == "Production" && getenv("HTTP_HOST") == "www.domain.de"'Which would lead to duplicate content though. So I think you actually want to setup a routing that forwards fro www.domain.de to domain.de (or vice versa), which you could do completely outside of TYPO3 just with domain setup / htaccess. Or you could use the redirect module to setup a TYPO3-based redirection middleware step.
-
Marcus Förster commented 02/10/25, 22:29
i want to get rid of the ReWrites to have domain-free .htaccess and less redirects
expl. idea .. not tested!
RewriteCond %{ENV:TYPO3_CONTEXT} ^Production$ RewriteCond %{HTTP_HOST} \.de$ RewriteRule ^ /index.php?id=1&L=0 [END] RewriteCond %{ENV:TYPO3_CONTEXT} ^Production$ RewriteCond %{HTTP_HOST} \.com$ RewriteRule ^ /index.php?id=1&L=1 [END]therefore thought that baseVariants would to the “tunnel” trick for presenting the correct `cannonical` for .de/.com without “www.”
-
Georg Ringer commented and changed status
Needs FeedbackRejected 03/13/25, 19:51thanks for the detailed issue. However I will still reject it. This is not a bug. Even though for most people www and non www are the same and browser even hide the “www” to make it easier for many people but in reality this is really another domain.
you can use a redirect like
RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]to redirect all non www to www but in TYPO3 context, the one site got one domain or variants
-
Marcus Förster commented 03/13/25, 21:14
the idea ; use two domains w/o www. @ typo3 but also recognise www. with the same baseV. => will patch t3s’php internaly
fyi/ www. removing redirect .. https://stackoverflow.com/questions/60176153/#answer-60181749
RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} ^www\. [NC] RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC] RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]the additive counter version ..
RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Are you sure HTTP_HOST is exposed as an ENV var in your setup?
Usually you set ENV vars like TYPO3_CONTEXT and operate on those, or you set context to other custom ENV vars that you can check. Commonly PHP only exposes this in $_SERVER[] I believe? You could setup a test.php file in your server and see if
getenv('HTTP_HOST')really returns what you’re expecting?