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 Dave - October 19, 2016

Thanks Tim, 

We'll look into this.  

So to be clear, what the plugin does by default is currently to generate links with trailing slashes, but you want no trailing slashes.  And, you want any other URLs that aren't the officially generated one to redirect to the officially generated URL.  Is that right?

And would it work if it did that but WITH trailing slashes, or do you have as a requirement no trailing slashes? 

Let me know, thanks!

Dave Edis - Senior Developer
interactivetools.com

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]