How to serve only one URL version (with slash or without to slash) for SEO optimization

Hi everyone, I was researching a bit about SEO and found this article “To slash or to not slash” from Google Webmasters.

Turns out, you can choose any URL format, with a slash (https://www.mysite.com/about/) at the end or not (https://www.mysite.com/about).

However, they recommend using only one form. And use a 301 redirect to the other.

I tried a lot of things that I’m going to list below, but none of them worked.

Has anyone solved this issue or have any idea on how to solve?

Since Middleman only generates static HTML files, it is up to the web server to determine what urls are used to access each file. With Apache, for example, about.html can be accessed at /about.html or /about when Multiviews is enabled. Therefore, depending on how you serve your site, you will need to configure the web server in question.

On the other hand, consider setting the canonical url tag. It will tell search engines the correct url of a page, when it is accessed with an alias, among other benefits.

Hope this helps.

1 Like

I prefer trailing slashes. Have you tried something like this in .htaccess (code from moz.com )
# Ensure all URLs have a trailing slash. RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301]

1 Like

Thanks @vvasabi! it will help indeed. I’ll test this solution.

@Charles I’m using Heroku to host my Middleman project and as far as I know, I can’t use .htaccess. But thanks for the help anyway!