Skip to content

is_homepage is always false when trailing slashes are enforced #15612

Closed

Description

@jhhazelaar

Bug description

With URL::enforceTrailingSlashes() enabled, the is_homepage cascade variable is never true, not even on the homepage.

Cascade compares $this->site->absoluteUrl() with $this->request->url():

'is_homepage' => $this->site->absoluteUrl() == $this->request->url(),

With trailing slashes enforced, Site::url() keeps the trailing slash through URL::tidy(), so absoluteUrl() returns https://example.test/. Laravel's Request::url() always strips the trailing slash and returns https://example.test, so the two never match.

I expected is_homepage to be true on the homepage regardless of the trailing slash setting.

How to reproduce

  1. Add URL::enforceTrailingSlashes(); to AppServiceProvider::boot().
  2. Put {{ is_homepage ? 'home' : 'not home' }} in a template and visit /.
  3. It renders "not home". Without enforceTrailingSlashes() it renders "home".

Logs

No response

Environment

Environment
Laravel Version: 13.31.0
PHP Version: 8.5.11
Composer Version: 2.10.3
Environment: local
Debug Mode: ENABLED
Maintenance Mode: OFF
Timezone: Europe/Amsterdam
Locale: nl

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: mariadb
Logs: stack / single, flare
Mail: log
Queue: sync
Session: file

Storage
public/assets: LINKED
public/storage: LINKED

Locales
Installed: en, nl
LaravelLang\Lang\Plugin: 15.34.8
Locales Version: 2.11.0
Protected: en, nl
Publisher Version: 16.8.0

Livewire
Livewire: v4.4.4

Statamic
Addons: 4
License Key: Set
Sites: 1
Stache Watcher: Enabled
Static Caching: Disabled
Version: 6.31.0 PRO

Statamic Addons
concept7/statamic-favorites: 1.0.0
eminos/statamic-tabs: 2.0.1
statamic/importer: 2.2.0
statamic/seo-pro: 7.14.1

Installation

Starter Kit using via CLI

Additional details

The comparison is unchanged on the current 6.x branch (v6.35.1). Stripping the trailing slash from the site URL before comparing fixes it; I'll open a PR with that change and tests.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions