I created pagination like example.com/shop/1 and example.com/shop/2,3,4,5... on shop.php i want to redirect the example.com/shop/1 to the example.com/shop only for no duplicate content issues. When i am using header redirect i am getting the header already sent error. Where i am mistaking?
<?php
require_once 'header.php';
$limit = 1;
$posts->post_type = 'products';
$currentPage = (isset($params['paged']) && is_numeric($params['paged']) ) ? $params['paged'] : 1;
$total_records = $posts->get_posts_total_record();
$pagination = new Pagination($currentPage, $total_records, $limit, BASE_URL.'/shop/', '', '');
$paginationStart = ($currentPage - 1) * $limit;
$rows = $posts->get_posts(
array
(
"post_type" => 'products',
"start" => $paginationStart,
"limit" => $limit,
"order" => 'id',
"sort" => 'DESC', // DESC / ASC
//"offset" => $limit
)
);
$rowsCount = $rows->rowCount();
?>
<section class="inner-header">
<div class="title">Our Products</div>
<div class="breadcrumb"><a href="<?php echo BASE_URL; ?>">Home</a> / Our Products</div>
</section>
<section class="portfolio-page">
<div class="border"></div>
<div class="title">Products</div>
<div class="boxs">
<?php if($rowsCount > 0) { ?>
<?php
foreach($rows as $row) {
$meta = $posts->get_meta(
array
(
"post_id" => $row['id'],
"meta_key" => "video_url"
)
);
?>
<div class="box" data-url="<?php echo $meta['meta_value']; ?>" data-title="<?php echo $row['title']; ?>">
<?php echo $posts->get_thumbnail(array("id" => $row["id"],"featured" => true,"class" => 'featured',"width" => 370,"height" => 271)); ?>
<div class="content">
<div class="cont-title"><?php echo $row["title"]; ?></div>
<div class="cont-subtitle"><?php echo $row["excerpt"]; ?></div>
</div>
</div>
<?php } ?>
<?php } else { ?>
<?php echo 'Not Found!'; ?>
<?php } ?>
</div>
<?php if($rowsCount > 0) { ?>
<div class="d-flex justify-content flex-column align-items">
<?php echo '<div class="pagination-details">'.$pagination->getPaginationSummary().'</div>'; ?>
<?php echo '<div class="pagination">'.$pagination->getPaginationHtml().'</div>'; ?>
</div>
<?php } ?>
<div class="btns">
<a href="/order-now" class="btn">Get Started</a>
</div>
</section>
<?php
require_once 'footer.php';
?>