Add a trailing slash to requested urls

Without trailing slash URL shows URL count as a page and with trailing slash it’s count as directory. Search engine gives the high priority to directory in comparision of page.

The solution was to create a .htaccess rewrite rule that adds the trailing slashes to these urls.

Example – redirect all urls that doesn’t have a trailing slash to urls with a trailing slash

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !example.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI}/ [L,R=301]

Share This Post

Post Comment