Issue Bug Rejected

#106143site:config languages baseVariants condition `getenv` matches

Marcus Förster 02/10/25, 15:11 updated 03/13/25, 21:14

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

  1. Garvin Hicking commented and changed status New Needs Feedback <span data-processor="relativetime" data-value="2025-02-10T17:10:58+00:00" > 02/10/25, 17:10 </span>

    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?

  2. Marcus Förster commented <span data-processor="relativetime" data-value="2025-02-10T17:51:22+00:00" > 02/10/25, 17:51 </span>

    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
  3. Garvin Hicking commented <span data-processor="relativetime" data-value="2025-02-10T19:23:45+00:00" > 02/10/25, 19:23 </span>

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

  4. Marcus Förster commented <span data-processor="relativetime" data-value="2025-02-10T19:48:46+00:00" > 02/10/25, 19:48 </span>

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

  5. Marcus Förster commented <span data-processor="relativetime" data-value="2025-02-10T19:58:35+00:00" > 02/10/25, 19:58 </span>

    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"'
  6. Marcus Förster commented <span data-processor="relativetime" data-value="2025-02-10T20:05:01+00:00" > 02/10/25, 20:05 </span>

    btw/
    applicationContext == "Production" && getenv("HTTP_HOST") ends with ".com"
    also does not work
  7. Garvin Hicking commented <span data-processor="relativetime" data-value="2025-02-10T20:07:28+00:00" > 02/10/25, 20:07 </span>

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

  8. Marcus Förster commented <span data-processor="relativetime" data-value="2025-02-10T20:33:57+00:00" > 02/10/25, 20:33 </span>

    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$#"'
  9. Garvin Hicking commented <span data-processor="relativetime" data-value="2025-02-10T21:19:40+00:00" > 02/10/25, 21:19 </span>

    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.

  10. Marcus Förster commented <span data-processor="relativetime" data-value="2025-02-10T22:29:38+00:00" > 02/10/25, 22:29 </span>

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

  11. Georg Ringer commented and changed status Needs Feedback Rejected <span data-processor="relativetime" data-value="2025-03-13T19:51:38+00:00" > 03/13/25, 19:51 </span>

    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

  12. Marcus Förster commented <span data-processor="relativetime" data-value="2025-03-13T21:14:03+00:00" > 03/13/25, 21:14 </span>

    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]