SEO Friendly URLs with no trailing slash

By goodonyx - October 18, 2016

Hi,

I'm using the latest CMSB and Permalinks plugin and would like to know if there is a way to enforce a "No-trailing Slash" option to prevent duplicate URLs for SEO purposes.

For example, the page below is accessible 2 ways using the standard .htaccess that is installed with the Permalinks plugin.

1) http://www.domain.com/page/

and

2) http://www.domain.com/page

I'm looking for a way that the first example is redirected to second example in all requests.

thanks,

Tim

By goodonyx - October 19, 2016

Hi Dave,

I don't think it's an issue with the plugin since it makes both URLs (with and without the slash) available. I think that is a good thing for users. Just for search engines it would be good to enforce a standard for one or the other just like you do for www or non-www enforcement. 

I was able to get the desired result of no trailing slash using the following code in the .htaccess file above the "force www. prefix code"

### Remove trailing slash
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]