PHPackages                             alpacadotsh/magento2-store-router - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. alpacadotsh/magento2-store-router

ActiveMagento2-module[Utility &amp; Helpers](/categories/utility)

alpacadotsh/magento2-store-router
=================================

Magento 2 store routing rules and definitions.

0.2.2(3mo ago)04.5k↓50%PHP

Since Jul 6Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/alpacash/store-router)[ Packagist](https://packagist.org/packages/alpacadotsh/magento2-store-router)[ RSS](/packages/alpacadotsh-magento2-store-router/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (11)Used By (0)

Magento 2 Store Router
======================

[](#magento-2-store-router)

This package will allow you to maintain specific rules based on http request conditions. We can add additional rules or conditions to this module whenever they are required.

Configuration yaml file
-----------------------

[](#configuration-yaml-file)

The configuration file is located your project's root and named `.store-router.app.yaml`.

### Example configuration file

[](#example-configuration-file)

```
mywebsite:
  rules:
    mage_run_code: 'mywebsite'

mywebsite-prod:
  inherit: mywebsite
  conditions:
    hosts:
      '*.mywebsite.com': '*'

mywebsite-staging:
  inherit: mywebsite
  conditions:
    hosts:
      'staging.mywebsite.com': '*'
  rules:
    auth: 'user:pass'
```

### Configuration groups

[](#configuration-groups)

In the example configuration file above, the groups are named “mywebsite”, “mywebsite-prod”, and “mywebsite-stagin”. Every group has it's own unique identifier.

### Inherit another group's data

[](#inherit-another-groups-data)

It's possible to inherit another group's data and merge or override it where necessary. Like we did in the example above, we can create one group which holds the rule for the `mage_run_code` and inherit the rules in every other group to avoid maintenance of duplicate content.

### Configuration group conditions

[](#configuration-group-conditions)

For now, the the request hostname will be the only possible type of conditions we have. This concludes the items from the `conditions` field in the example configuration file above. We can add additional conditions by extending `src/Config/ConditionCollection.php` .

#### Configuration condition: hosts

[](#configuration-condition-hosts)

The hostnames are matched using the `fnmatch()` function, meaning we can use wildcards. So in order to apply a certain rule for every subdomain of `example.com`, we can use `*.example.com` in the configuration as shown in the example above.

The value for every hostname in the configuration should be the request paths the rules should be applied for. The request path can be either a string or an array. Here's an example:

```
# Multiple paths
'*.example.com':
    - 'nl-be'
    - 'de-de'
# Wildcard, meaning the rules
# should apply to every request path
'*.example.uk': '*'
```

### Configuration group rules

[](#configuration-group-rules)

Our rules are defined in the yaml configuration file under the `rules` field for every condition group. These can be inherited as well. We can implement additional rules by adding a key to the `ruleMapping` field in `src/Config/RuleCollection.php`, having the responsible `RuleContract` class name as it's value. For example, see `src/Rule/BasicAuth.php`.

#### Configuration rule: mage\_run\_code

[](#configuration-rule-mage_run_code)

We can define the MAGE\_RUN\_CODE property to persist a specific Magento store code and make sure to always load a specific Magento store, based on our defined http conditions. This way we can make sure to always display the `example_uk` store whenever someone visits `//example.com/uk`.

#### Configuration rule: auth

[](#configuration-rule-auth)

Based on http conditions, we can define specific http basic auth credentials in order to block access to the public. This is especially required for staging environments. The example below shows us how to define http basic auth credentials for `staging.example.com`, while maintaining public access for the production environment `example.com`.

```
'example':
    'conditions':
        'hosts':
            'example.com': '*'

'staging.example.com':
    'conditions':
        'hosts':
            'staging.example.com': '*'
    'rules':
        'auth': 'user:pass'
```

##### IP address whitelisting

[](#ip-address-whitelisting)

It is possible to whitelist a range of ip-addresses and allow their access without authentication. Add the whitelisted CIDR ranges to `app/etc/ip-whitelist/`, one per line. Note that it is possible to comment out and disable whitelist ranges using `#`.

**Example:**

```
127.0.0.1/24
8.8.8.8/16
# 8.8.4.4/16

```

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance79

Regular maintenance activity

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~207 days

Recently: every ~382 days

Total

9

Last Release

112d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d91a0b4cc171050631054998d45aaf17035f28a351a218a8809ac7daa364da48?d=identicon)[imadphp](/maintainers/imadphp)

---

Top Contributors

[![imadphp](https://avatars.githubusercontent.com/u/33043295?v=4)](https://github.com/imadphp "imadphp (12 commits)")[![HyperC](https://avatars.githubusercontent.com/u/5372580?v=4)](https://github.com/HyperC "HyperC (2 commits)")

### Embed Badge

![Health badge](/badges/alpacadotsh-magento2-store-router/health.svg)

```
[![Health](https://phpackages.com/badges/alpacadotsh-magento2-store-router/health.svg)](https://phpackages.com/packages/alpacadotsh-magento2-store-router)
```

###  Alternatives

[netgen/layouts-core

Netgen Layouts enables you to build and manage complex web pages in a simpler way and with less coding. This is the core of Netgen Layouts, its heart and soul.

3689.4k10](/packages/netgen-layouts-core)[netgen/content-browser

Netgen Content Browser is a Symfony bundle that provides an interface which selects items from any kind of backend and returns the IDs of selected items back to the calling code.

14112.1k8](/packages/netgen-content-browser)[mapbender/mapbender

Mapbender library

10117.4k5](/packages/mapbender-mapbender)[leapt/core-bundle

Symfony LeaptCoreBundle

2529.1k4](/packages/leapt-core-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
