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. If a URL is not terminated using a trailing slash, it generally points to a file. However, these are just 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 hardly contains any 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. The reason is because individual content should only be accessible through a single URL. Apart from the loss of confidence from Google due to the spread of duplicate content, the multiple indexing can also hurt the website in other ways. By indexing several URL duplicates, the incoming traffic is divided into different placements in the SERPs. As a result, it is often difficult for the different domain variants to establish themselves in the search engine rankings. Therefore, several URLs index in the search engine, but none of these URLs rank well because the search engine cannot choose one of them. Therefore, it is preferable to choose one option. This is the only way to prevent unwanted duplicate content from entering the index.


Avoiding duplicate content

The following is recommended to ensure that the content of a website does not appear multiple times in the index through a modified URL: Use of the HTTP status code 301 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.