Issue Description
Every few months we have a discussion about trailing slashes in urls.
This tweet from John Mueller should clear it up
How to Fix the Issue
At the root, trailing slash/none trailing slash doesn’t matter.
So:
issues.cargocreative.co.uk
and
issues.cargocreative.co.uk/
Are treat the same.
Elsewhere it does matter, so:
issues.cargocreative.co.uk/back-end
and
issues.cargocreative.co.uk/back-end/
Are treat differently so open to duplicate content penalties.
Note on the code for htaccess – most solutions cause wordpress to break on form submissions – I’ve learned the hard way, so the solution below excludes posts to wp-admin and wp-json which solves most contact form issues.
Fixed Code Snippets
# Force trailing slash in WP without damaging the admin interface or the JSON API
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/wp-json
RewriteCond %{REQUEST_URI} !^/wp-admin
RewriteCond %{REQUEST_URI} !^/([_0-9a-zA-Z-]+)/wp-json
RewriteCond %{REQUEST_URI} !^/([_0-9a-zA-Z-]+)/wp-admin
RewriteRule ^([^.]+)([^./])$ %{REQUEST_URI}/ [L,R=301,NE]
</IfModule>
References
Reference Description |
Reference Link |
---|---|
John's tweet |
View Page |