Skip to content

Redirect paginated homepage requests to the homepage - #3694

Open
muneeb-ashraf wants to merge 1 commit into
WordPress:trunkfrom
muneeb-ashraf:fix/2480-paged-home-redirect
Open

muneeb-ashraf wants to merge 1 commit into
WordPress:trunkfrom
muneeb-ashraf:fix/2480-paged-home-redirect

Conversation

@muneeb-ashraf

Copy link
Copy Markdown

Fixes #2480.

What

Paginated views of the homepage, such as https://learn.wordpress.org/page/4/, currently return a 200 with the homepage content. This adds a template_redirect handler in inc/redirects.php that sends them to the homepage with a 301, next to the existing redirects.

The check covers both ways WordPress can represent /page/N/ on the front page:

  • is_paged() when the front page shows the latest posts.
  • get_query_var( 'page' ) > 1 when a static page is the front page, since WordPress moves paged to page in that case.

Paginated archives, search results and the first page of the homepage are not affected.

Testing

I ran these cases against WordPress trunk with a throwaway PHPUnit test that loads inc/redirects.php and fires template_redirect:

Request Front page setting Result
/page/2/ Static page 301 to /
/page/2/ Latest posts 301 to /
/ Static page No redirect
/category/news/page/2/ Latest posts No redirect
/page/2/?s=post Latest posts No redirect

Without the change, the two /page/2/ cases don't redirect (core's redirect_canonical() leaves them alone). composer run lint rules pass on the changed file.

To check manually after deploy: curl -sI https://learn.wordpress.org/page/4/ should return 301 with Location: https://learn.wordpress.org/.

AI assistance
  • AI assistance: Yes
  • Tool: Claude Code
  • Model: Claude Opus 5.5
  • Used for: Code and tests. I reviewed and ran the tests myself.

🤖 Generated with Claude Code

https://claude.ai/code/session_01W6LxjEQnP4PPgXXvAM3M2F

Requests such as /page/4/ returned a 200 with the homepage content.
Send them to the homepage with a 301 instead.

Fixes WordPress#2480.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W6LxjEQnP4PPgXXvAM3M2F
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Requests to paginated views of the homepage should redirect to the homepage

1 participant