Trailing Slashes

A trailing slash is the forward slash placed at the end of a URL. The trailing slash is generally used to mark a directory, and if a URL is not terminated using a trailing slash, this generally points to a file. However, these are guidelines, and not requirements. The process of setting a single trailing slash for directories has established itself as a standard over time. The slashes play an important role in search engine optimization, especially in the area of duplicate content.

Trailing slashes and SEO

Although the trailing slash in a URL does not contain concrete information, its importance in search engine optimization cannot be ignored. This should be taken into account mostly in cases where websites can be accessed through a URL with a different number of trailing slashes, such as a page that can be opened with two or no trailing slashes. This results in duplicate content which, according to Google, should be avoided. This is because individual content should only be accessible through a single URL.

This multiple indexing can negatively effect the website in ways other than creating duplicate content, which causes confusion for Google. If several URLs are indexed, the incoming traffic is divided into different placements in the SERPs. It is therefore difficult for the different domain variants to establish themselves in the search engine rankings. Therefore, there may be several URLs in the search engine index, but none of these URLs rank well because the search engine has to choose between them.

Therefore, it is preferable to choose one option: either with or without a trailing slash. This is the only way to prevent unwanted duplicate content from entering the index.


Avoiding duplicate content

To ensure the content of a website does not appear multiple times in the index through a modified URL, you should use a 301 redirect to redirect between domains. This way, incoming traffic can be re-bundled and directed to the actual and only target page. Thus, the URL duplicated using trailing slashes loses its validity.

Removing trailing slashes with the re-write rule

To remove a trailing slash from the URL, the following code should be included in the .htaccess file of the web server:

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

Significance in practice

Incorrectly set trailing slashes may cause search engines to ignore the appropriate indication when using canonical tags. For this reason, the URL specified in the Canonical tag must also contain the trailing slash, if one exists. The same applies to the country identification of URLs using hreflang or to the forwarding of URLs via 301 redirect. If there are no slashes in these cases, the country assignment can fail or pages are not redirected correctly.