In the Matomo Page URL reports, your website’s homepage is typically represented as either the root path / or /index, depending on the report structure: flat or hierarchical. Both entries refer to the same page but are displayed differently based on the report view. The appearance of the homepage URL depends on the selection in the report’s settings report settings green cog icon.

In a flat view, Matomo shows all pages at the same level and the homepage appears as a root path /.

page report flat view

In a hierarchical view, Matomo breaks down the report structure into nested paths to reflect the layout of your website. However, the homepage does not have a parent path to nest under, so for consistent hierarchical formatting, Matomo represents the homepage as /index. This indicates its the root page, while maintaining the format of the path-based structure.

page report hierarchical view

This can help users navigate reports differently depending on whether they want to analyse grouped paths or individual URLs.

Note: This does not impact data accuracy. Both entries refer to the same tracked page and metrics like pageviews and bounce rate are still accurately recorded for the correct page.

How to group homepage URLs

In some websites, the homepage can be accessed through multiple URLs, such as /, /index, and /index.html. If visitors access these URLs directly, Matomo records them as separate page URLs, causing homepage traffic to be split across multiple rows in the Pages report.

To report homepage traffic under a single URL, you can either redirect visitors to a canonical homepage URL or rewrite the URL before it is sent to Matomo.

grouping homepage urls

After grouping homepage URLs, the change will only affect new pageviews collected after the change is implemented. Follow the approach below that is compatible with your setup.

The most reliable solution is to configure permanent (301) redirects so that all homepage variations redirect to a single canonical URL. For example, redirecting /index and /index.html to /.

This solution does not require any changes to the tracking code. It creates a single homepage entry in Matomo reports and improves data consistency.

Option 2: Rewrite the URL before sending data to Matomo

If redirects cannot be implemented, you can standardise the page URL before it is sent to Matomo. This requires a change to tracking using either Matomo Tag Manager or custom JavaScript.

Configure Tag Manager

  1. Open your Tag Manager container and go to Variables.
  2. Click Create New Variable and choose the Custom JavaScript variable type.
  3. Add a Custom JavaScript variable that checks the current URL and replaces /index or /index.html with / before the pageview is sent to Matomo.
  4. Update the Matomo tracking tag to use the new variable for the Custom URL. In the Custom URL field, select the Custom JavaScript variable you created.

This first example rewrites /index and /index.html to / while preserving any query parameters and URL fragments. Campaign parameters, such as utm_campaign, utm_source, and pk_campaign, continue to be processed by Matomo, so campaign attribution remains unaffected.

// EXAMPLE 1

function(){
    var url = new URL(window.location.href);

    if (url.pathname === '/index' || url.pathname === '/index.html') {
        url.pathname = '/';
    }

    return url.href;
}

The second example groups all homepage variations under /, including URLs that contain query parameters or URL fragments. Use this approach if you want all homepage traffic to appear under a single Page URL in reports. Campaign parameters are still processed by Matomo before the pageview is tracked, so campaign attribution remains unaffected.

// EXAMPLE 2
function() {
    var url = new URL(window.location.href);

    if (
        url.pathname === '/' ||
        url.pathname === '/index' ||
        url.pathname === '/index.html'
    ) {
        return url.origin + '/';
    }

    return url.href;
}

Test the setup in Preview/Debug mode before publishing the container.

Configure JavaScript tracking

If you use JavaScript tracking instead of Tag Manager, set a custom URL before calling trackPageView.

This first example rewrites /index and /index.html to / while preserving any query parameters and URL fragments. Campaign parameters, such as utm_campaign, utm_source, and pk_campaign, continue to be processed by Matomo, so campaign attribution remains unaffected.

// EXAMPLE 1
<script>
  var _paq = window._paq = window._paq || [];

  var url = new URL(window.location.href);

  if (url.pathname === '/index' || url.pathname === '/index.html') {
      url.pathname = '/';
  }

  _paq.push(['setCustomUrl', url.href]);

  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);

  (function() {
    var u = "https://your-matomo.example/";
    _paq.push(['setTrackerUrl', u + 'matomo.php']);
    _paq.push(['setSiteId', '1']);
    var d = document, g = d.createElement('script'),
        s = d.getElementsByTagName('script')[0];
    g.async = true;
    g.src = u + 'matomo.js';
    s.parentNode.insertBefore(g, s);
  })();
</script>

The second example groups all homepage variations under /, including URLs that contain query parameters or URL fragments. Use this approach if you want all homepage traffic to appear under a single Page URL in reports. Campaign parameters are still processed by Matomo before the pageview is tracked, so campaign attribution remains unaffected.

// EXAMPLE 2
<script>
  var _paq = window._paq = window._paq || [];

  var url = new URL(window.location.href);

  if (
      url.pathname === '/' ||
      url.pathname === '/index' ||
      url.pathname === '/index.html'
  ) {
      url = new URL(url.origin + '/');
  }

  _paq.push(['setCustomUrl', url.href]);

  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);

  (function() {
    var u = "https://your-matomo.example/";
    _paq.push(['setTrackerUrl', u + 'matomo.php']);
    _paq.push(['setSiteId', '1']);
    var d = document, g = d.createElement('script'),
        s = d.getElementsByTagName('script')[0];
    g.async = true;
    g.src = u + 'matomo.js';
    s.parentNode.insertBefore(g, s);
  })();
</script>

Option 3: Use an action-scope custom dimension

You can use an Action Custom Dimension to extract a normalised homepage value from the Page URL. This creates a separate dimension report in the Behaviour menu where homepage variants are grouped under /.

⚠️ Important: This approach strips query parameters and fragments from the Custom Dimension value. Campaign parameters are not preserved in this Custom Dimension value. Use server-side redirects or the tracking-code approach if campaign attribution must be preserved.

  1. Go to Administration admin gear icon> Websites (or Measurables) > Custom Dimensions.
  2. Create a new Action Custom Dimension.
  3. Choose Page URL as the extraction source and add the regex:
    ^https?://[^/]+(/)(?:index(?:\.html|\.php)?|home)?(?:[?#].*)?$
  4. This example regex only affects URLs that match the patterns defined in the regular expression, such as /, /index, /index.html, /index.php, and /home. These are grouped in Behaviour > dimension report.
  5. Other URLs are not modified unless they are explicitly included in the regular expression.
  6. If your website uses other homepage variations, such as /default.aspx or /homepage, you will need to modify the regex to include those URLs.

Which approach should I use?

In most cases, server-side 301 redirects are the recommended solution because they prevent duplicate homepage URLs from being generated in the first place. This improves data consistency across analytics and search engines and does not require any tracking modifications.

  • If redirects are not possible, standardise homepage URLs using Matomo Tag Manager or JavaScript tracking. These methods preserve campaign parameters and URL fragments when configured correctly, allowing homepage traffic to be grouped in the standard Pages report without affecting campaign attribution.
  • Using an action scope Custom Dimension can be useful if you cannot modify tracking but it comes with caveats. It groups URLs in a separate dimension report and campaign parameters and URL fragments are not preserved, which affects campaign attribution.

Note: All approaches only affect data collected after the change is implemented. Historical data remains unchanged, and existing homepage URL entries will continue to appear separately in past reports.

Previous FAQ: What is the maximum URL length and how do I track long Page URLs and Page Titles without truncating them?