Project

General

Profile

Actions

Bug #106143

closed

site:config languages baseVariants condition `getenv` matches

Added by Marcus Förster about 1 month ago. Updated 11 days ago.

Status:
Rejected
Priority:
Should have
Assignee:
-
Category:
Site Handling, Site Sets & Routing
Target version:
-
Start date:
2025-02-10
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
11
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

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?

Actions #1

Updated by Marcus Förster about 1 month ago

  • Description updated (diff)
Actions #2

Updated by Garvin Hicking about 1 month ago

  • Status changed from New to Needs Feedback

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?

Actions #3

Updated by Marcus Förster about 1 month ago · Edited

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
Actions #4

Updated by Garvin Hicking about 1 month ago

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....?

Actions #5

Updated by Marcus Förster about 1 month ago

yea (tested) but regex does not care if / or #; first char will be last char (or error)

Actions #6

Updated by Marcus Förster about 1 month ago

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"'
Actions #7

Updated by Marcus Förster about 1 month ago

btw/

applicationContext == "Production" && getenv("HTTP_HOST") ends with ".com"
also does not work

Actions #8

Updated by Garvin Hicking about 1 month ago

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...?

Actions #9

Updated by Marcus Förster about 1 month ago · Edited

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$#"'

Actions #10

Updated by Garvin Hicking about 1 month ago

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.

Actions #11

Updated by Marcus Förster about 1 month ago · Edited

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."

Actions #12

Updated by Georg Ringer 11 days ago

  • Status changed from Needs Feedback to Rejected

thanks 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

Actions #13

Updated by Marcus Förster 11 days ago · Edited

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]
Actions

Also available in: Atom PDF