Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

skip appending page=1 in pagination URLs #55772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: 12.x
Choose a base branch
Loading
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions 16 src/Illuminate/Pagination/AbstractPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,25 @@ public function url($page)
$page = 1;
}

// Only add the page parameter if it's greater than 1.
// This prevents unnecessary ?page=1 in the URL and improves SEO by avoiding duplicate content.
$parameters = $page > 1 ? [$this->pageName => $page] : [];

// If we have any extra query string key / value pairs that need to be added
// onto the URL, we will put them in query string form and then attach it
// to the URL. This allows for extra information like sortings storage.
$parameters = [$this->pageName => $page];

if (count($this->query) > 0) {
$parameters = array_merge($this->query, $parameters);
}

// Build the query string and attach it to the path
$query = Arr::query($parameters);

return $this->path()
.(str_contains($this->path(), '?') ? '&' : '?')
.Arr::query($parameters)
.$this->buildFragment();
. ($query === ''
? ''
: (str_contains($this->path(), '?') ? '&' : '?') . $query)
. $this->buildFragment();
Comment on lines +199 to +206
Copy link
Contributor

@shaedrich shaedrich May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might just use the Uri class here:

Suggested change
// Build the query string and attach it to the path
$query = Arr::query($parameters);
return $this->path()
.(str_contains($this->path(), '?') ? '&' : '?')
.Arr::query($parameters)
.$this->buildFragment();
. ($query === ''
? ''
: (str_contains($this->path(), '?') ? '&' : '?') . $query)
. $this->buildFragment();
return Uri::of($this->path())->withQuery($query)->withFragment($this->buildFragment);

}

/**
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.