🌱 The next big step: Kirby 4 Beta Learn more
Skip to content

Quicktip: To slash or not to slash

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. You have to exempt the API and the Panel from the rule to prevent breaking the Panel and the media folder to prevent breaking media files and thumbs.

# force trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/api
RewriteCond %{REQUEST_URI} !^/panel
RewriteCond %{REQUEST_URI} !^/media
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
RewriteCond %{REQUEST_URI} !^/media
RewriteRule ^(.*)/$ /$1 [L,R=301]