magento / magento/magento-cloud

less strict string matching in magento-vars.php

Open
#446 9 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
226
Forks
244
PR merge metrics
No merged PRs in 30d

Description

The isHttpHost() function has very strict string matching. This requires a new block of code utilizing the function to be created for each new environment.

For example:

```
if (isHttpHost("www.examplea.com")) {
$_SERVER["MAGE_RUN_CODE"] = "default";
$_SERVER["MAGE_RUN_TYPE"] = "store";
}
if (isHttpHost("mcstaging.examplea.com")) {
$_SERVER["MAGE_RUN_CODE"] = "default";
$_SERVER["MAGE_RUN_TYPE"] = "store";
}
if (isHttpHost("examplea.branchname-zrgukpa-kolnt6awfmkyd.us-3.magentosite.cloud")) {
$_SERVER["MAGE_RUN_CODE"] = "default";
$_SERVER["MAGE_RUN_TYPE"] = "store";
}
if (isHttpHost("examplea.test")) {
$_SERVER["MAGE_RUN_CODE"] = "default";
$_SERVER["MAGE_RUN_TYPE"] = "store";
}
if (isHttpHost("www.exampleb.com")) {
$_SERVER["MAGE_RUN_CODE"] = "storeb";
$_SERVER["MAGE_RUN_TYPE"] = "store";
}
if (isHttpHost("mcstaging.exampleb.com")) {
$_SERVER["MAGE_RUN_CODE"] = "storeb";
$_SERVER["MAGE_RUN_TYPE"] = "store";
}
if (isHttpHost("exampleb.branchname-zrgukpa-kolnt6awfmkyd.us-3.magentosite.cloud")) {
$_SERVER["MAGE_RUN_CODE"] = "storeb";
$_SERVER["MAGE_RUN_TYPE"] = "store";
}
if (isHttpHost("exampleb.test")) {
$_SERVER["MAGE_RUN_CODE"] = "storeb";
$_SERVER["MAGE_RUN_TYPE"] = "store";
}
```

Also, the default function does not accommodate domain name differentiators that may occur at the end of the domain name. For example:

- example.com
- example.co.uk

I propose a more flexible string matching that would allow for one block of code to identify a store in all environments. For example:

```
if (isHttpHost("examplea")) {
$_SERVER["MAGE_RUN_CODE"] = "default";
$_SERVER["MAGE_RUN_TYPE"] = "store";
}
if (isHttpHost("exampleb")) {
$_SERVER["MAGE_RUN_CODE"] = "storeb";
$_SERVER["MAGE_RUN_TYPE"] = "store";
}
```

This is a better fit for Magento's dynamic system of hostname creation.

Personally, I always change the function to have more flexible string matching in my own projects. But, I notice that many people on Community Engineering Slack mistakenly assume that the function can't be changed. They rely on the function provided and are frustrated by it.

This is my own preference:

```
function isHttpHost($host)
{
if (!isset($_SERVER['HTTP_HOST'])) {
return false;
}
return strpos(str_replace('---', '.', $_SERVER['HTTP_HOST']), $host) !== false;
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in magento-vars.php by reading isHttpHost() and the surrounding hostname-based Magento configuration. Compare its current behavior with the example domains and proposed flexible matching, including hosts with differing suffixes. Done means one store configuration can cover the intended environments without breaking the missing-HTTP_HOST case.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.