Avoid duplicate content on pretty URLs with htaccess

To ensure that your URLs have a consistent trailing slash and avoid duplicate content, you can use the following .htaccess rules. These rules will enforce a single trailing slash for URLs and redirect any URLs without or with multiple trailing slashes to their correct form.

Here’s the updated .htaccess code:

# Enable rewrite engine
RewriteEngine On

# Remove multiple trailing slashes
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule ^ %1/%2 [R=301,L]

# Redirect URLs with trailing slash to without (only for URLs not ending with a file extension)
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+?)/$ /$1 [R=301,NE,L]

# Add trailing slash if not present (except for existing files and URLs with file extensions)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.[^./]+$
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ /$1/ [R=301,L]

techhipbettruvabetnorabahisbahis forumuedueduseduseduedusedueduseduedusedus