php – How to remove duplicate pages?


Hello to all!

Now the page is available at site.loc/page/2 and site.loc/index.php?view=page&page_id=3 . The engine is self-written.


RewriteEngine On
RewriteRule ^page/(\d+)/?$ index.php?view=page&page_id=$1

The question is: how can I remove duplicates via .htaccess or php? In short, you need to redirect from site.loc/index.php?view=page&page_id=3 to site.loc/page/2 .


RewriteCond %{HTTP_HOST} ^index.php$
RewriteRule ^index.php?view=(.*)&page_id=(.*)$ http://site.loc/$1/$2 [L,R=301]

Something like this, but here the question is how for me it should be just in the SEO part, since the moment that the page is available at several addresses is not a problem, but the fact that search engines index them separately is already a problem. As the commenter posted above rel = canonical will solve the problem!

For example, the OpenCart engine is very sinful in that you can access the page via the CNC, along the full path with the category and post through the GET, and directly by the record ID, and at the same time, the canonical path is very difficult to properly configure.

Scroll to Top