Orange Collar Media
Orange Collar Media
DOCS
ORANGECOLLAR/MODULE-WORDPRESS-INTEGRATION · URL ROUTING

URL Routing

  • Magento
  • Adobe Commerce
  • Hyvä

The Controller/Router.php class implements Magento\Framework\App\RouterInterface and intercepts all requests matching the configured blog base path.

Route Resolution Order

The router tries each pattern in order. The first match wins.

PatternExample URLControllerActionParams
Blog listing/blogblogindex-
Paginated listing/blog/page/2blogindexpage=2
Category archive/blog/category/newscategoryviewslug=news
Category paginated/blog/category/news/page/2categoryviewslug=news, page=2
Tag archive/blog/tag/magentotagviewslug=magento
Author archive/blog/author/johnauthorviewslug=john
Search/blog/searchsearchresults(query via GET)
Single post/blog/my-post-slugpostviewslug=my-post-slug

The single-post catch-all pattern is always last. It matches any single path segment that does not match a more specific pattern above.

How the Router Works

PHP
public function match(RequestInterface $request): ?ActionInterface
{
    // 1. Check module is configured (URL + API key set)
    if (!$this->config->isConfigured()) {
        return null;
    }

    // 2. Check URL starts with blog base path
    $identifier = trim($request->getPathInfo(), '/');
    $basePath = $this->config->getBlogBaseUrl();

    if (!str_starts_with($identifier, $basePath)) {
        return null;
    }

    // 3. Resolve the remaining path segment
    $path = substr($identifier, strlen($basePath) + 1);
    $result = $this->resolveRoute($path);

    // 4. Set request params and dispatch
    $request->setModuleName('wordpress');
    $request->setControllerName($result['controller']);
    $request->setActionName($result['action']);
    // ...
}

Configurable Base Path

The base path is read from orangecollar_wordpress/blog/base_url in Magento system config. It defaults to blog but can be changed to any alphanumeric string (e.g., news, articles, journal).

If you change the base path, flush the Magento cache. Any hardcoded links in content must also be updated (or rely on the link rewriting in ContentProcessor).

Router sortOrder

The WordPress router runs at sortOrder 25 in Magento’s router list. The standard Magento router list order is:

sortOrderRouter
10Admin
20Robots/Sitemap
25WordPress (this module)
30Standard Magento URL rewrites
100CMS
200Default (404)