Skip to content
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

fix(pagination): ensure canonical URLs exclude ?page=1 #70

Merged
merged 1 commit into from
Jan 16, 2025

Conversation

atiksoftware
Copy link
Contributor

This commit updates the setPaginationLinks method to ensure that the canonical URL for the first page does not include ?page=1. Including this parameter can create SEO issues by generating duplicate canonical tags for the same content, leading to potential penalties or confusion for search engines.

Changes:

  • Modified setPaginationLinks to check if the current page is greater than 1. If not, it sets the canonical URL to the base URL without ?page=1.
  • Updated test cases to reflect Laravel’s paginator behavior, ensuring canonical, next, and previous links are correctly formatted.
  • Ensured test coverage includes:
    • First page scenarios, where ?page=1 is excluded from canonical URLs.
    • Middle and subsequent pages, where all pagination links (next, prev, and canonical) are properly formatted with query parameters like ?page=n.

Example:

For the first page:

  • Canonical URL: http://site.com (without ?page=1).
  • Next link: http://site.com?page=2.

For page 10:

  • Canonical URL: http://site.com?page=10.
  • Next link: http://site.com?page=11.
  • Previous link: http://site.com?page=9.

Reason:

By excluding ?page=1 from canonical URLs on the first page, we avoid duplicate content issues in search engines, ensuring that the main content URL is consistent and SEO-friendly.

…mization

fix(pagination): ensure canonical URLs exclude `?page=1` for SEO optimization

This commit updates the `setPaginationLinks` method to ensure that the canonical URL for the first page does not include `?page=1`. Including this parameter can create SEO issues by generating duplicate canonical tags for the same content, leading to potential penalties or confusion for search engines.

### Changes:
- Modified `setPaginationLinks` to check if the current page is greater than 1. If not, it sets the canonical URL to the base URL without `?page=1`.
- Updated test cases to reflect Laravel’s paginator behavior, ensuring canonical, next, and previous links are correctly formatted.
- Ensured test coverage includes:
  - First page scenarios, where `?page=1` is excluded from canonical URLs.
  - Middle and subsequent pages, where all pagination links (`next`, `prev`, and canonical) are properly formatted with query parameters like `?page=n`.

### Example:
For the first page:
- Canonical URL: `http://site.com` (without `?page=1`).
- Next link: `http://site.com?page=2`.

For page 10:
- Canonical URL: `http://site.com?page=10`.
- Next link: `http://site.com?page=11`.
- Previous link: `http://site.com?page=9`.

### Reason:
By excluding `?page=1` from canonical URLs on the first page, we avoid duplicate content issues in search engines, ensuring that the main content URL is consistent and SEO-friendly.
@butschster butschster self-requested a review January 15, 2025 15:10
@butschster butschster self-assigned this Jan 15, 2025
@butschster butschster added the enhancement New feature or request label Jan 15, 2025
@butschster butschster merged commit 5608a65 into butschster:3.x Jan 16, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants