Skip to content

Quicktip: To slash or not to slash

How to enforce URLs with or without trailing slashes

Providing the same content on different URLs is usually considered problematic because of duplicate content and reduced crawl efficiency. It therefore makes sense to enforce either URLs with a trailing slash or without, i.e. have one redirect to the other.

Enforce trailing slash

The rule to enforce a trailing slash has to be placed after line #36 in the default .htaccess provided with Kirby's Starterkit, and you have to exempt the API and the Panel from the rule to prevent breaking the Panel.

# force trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/api
RewriteCond %{REQUEST_URI} !^/panel
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]

Enforce URLs without trailing slash

The extra rules for the Panel are not needed if you want to enforce URLs without a trailing slash, so these two lines will do the job:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/$ /$1 [L,R=301]