In this post I will demonstrate how to avoid one of the biggest SEO problems, which is duplicate content, that is, two or more URLs on your website display the same content. For SEO, this is terrible, as clicks and views are counted separately according to how your URL is written. Although it seems like just a detail, duplicate content is one of the biggest causes of bad rankings in search engines and content aggregators.
As a prerequisite for implementing the .htaccess code, your Apache server must already have the mod_rewrite module activated.
Using the codes I will show you below, we will be able to overcome this situation quickly and practically. It boils down to 3 types of redirects that will be performed by Apache:
- Insert www in the URL if you don't have one: Makes http://dominio.com.br and http://www.dominio.com.br represent the same URL. When typing the address without the WWW, Apache will redirect to the URL with the WWW automatically
- Remove / at the end of the link: Causes the “/” character to be removed at the end of URLs, causing http://www.dominio.com.br/ to be directed to http://www.dominio.com.br
- Remove index.php: Redirects the link http://www.dominio.com.br/index.php to http://www.dominio.com.br, avoiding content redundancy on the main page of your website
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirecionar http://dominio.com.br para http://www.dominio.com.br
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,NE,L]
# Retirar / no final do link
RewriteCond %{HTTP_HOST} !^\. [NC]
RewriteRule ^(.+[^/])/$ http://%{HTTP_HOST}/$1 [R=301,L]
# Remover o index.php
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)$ / [R=301,L]
</IfModule>
Comentários (0)
Carregando comentários…