Add or remove trailing slash. Which is the best solution?

add or remove trailing slash

There seems to be no difference between adding or removing the trailing slash. I always suggest to follow what the big company do. For example amazon, google, samsung are adding trailing slash. However, the important thing is to choose one solution. This is very important otherwise google  will see two valid page and this will be reported to you in the search console.  The page “mypage” can be reached using both of the following addresses:

https://www.example.com/mypage

https://www.example.com/mypages/

and this absolutely must not happen!

 

 

Add trailing slash under Windows Server

If you need to add a trailing slash and you are using a Windows server, run the IIS management console, choose website from the left menu, and click the URL Rewrite icon in the right panel. Here you can add the predefined rule “Add trailing slash” or, more simply edit, if you have a little experience, your web.config and copy add paste the following rule.

<rule name=”AddTrailingSlashRule” stopProcessing=”true”>

<match url=”(.*[^/])$” />

<conditions>

<add input=”{REQUEST_FILENAME}” matchType=”IsDirectory” negate=”true” />

<add input=”{REQUEST_FILENAME}” matchType=”IsFile” negate=”true” />

</conditions>

<action type=”Redirect” url=”{R:1}/” />

</rule>

 

Yoast and REST API access

FOR SEO Website optimization, we use YOAST SEO and Yoast WooCommerce SEO plugin. The number one of SEO plugin!!!

If you add trailing slash and you are using Windows server, most likely, you’ll get an error when you try to run “Start data SEO data optimization” under tools menu. It won’t work when you add “/” at the end of urls. Certainly other wordpress plugin/function could be involved in this problem, because wordpress add “/” to rest api call too, so you need to remove “/” in these case.

One solution would be to not add the trailing slash when we encounter the word wp-json in the path. To do this, just replace the regular expression

<match url=”(?=^(.*)([^/])$)^((?!wp-json).)*$” />

Run “Start data SEO data optimization” and now it works!

 

Video .mp4 and other extensions

When you add trailing shash probably you have to excude your video .mp4 and other extensions. To do this, just edit your web.config and copy and paste the following rule:

<rule name=”mp4″ stopProcessing=”true”>

<match url=”(.mp4)” />

<action type=”None” />

</rule>

Remember to place it before the traling slash rule!

NEWSLETTER SUBSCRIPTION



    I consent to the processing of my personal data for marketing purposes

    I accept the terms of privacy policy