Add or remove the trailing slash in URLs to ensure consistent URL structure, good for SEO.

Remove Trailing Slash

To standardize on URLs without a trailing slash at the end, add the following to .htaccess or virtual host config:

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

This rule will cause Apache to redirect requests which DO contain a slash at the end to the same URL with it removed. For SEO purposes, this type of redirect should be Permanent (301).

Why Lose Memories?

Add Trailing Slash

Alternatively, if you would like to always have a trailing slash on URLs, if it doesn’t end with one, add the following to .htaccess or virtual host config:

RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]

This rule causes Apache to redirect requests for URLs which do not end in a slash to the same URL with the trailing slash added. For SEO purposes, this type of redirect should be Permanent (301).