I have installed ssl in my Magento 2 store and configured base url to the https version.

But when accessing http version, Magento redirecting url with appending trailing slash.

For example:

My domain is example.com

Base url saved in configuration is https://www.example.com

When I accessing http version http://www.example.com/contactus.html

it is redirecting to https://www.example.com/contactus.html/

Could you please help to remove the trailing slash while redirecting.

  • Hi I have to remove trailing slash for cms page can U advise me how to do it? – Nagaraju K Aug 21 '20 at 2:44

Magento admin you can use store direct_url for remove trailing slash.


<a href="{{store direct_url='contact-us'}}">Contact</a>
  • Hi @savan patel i have tried this but no luck. Can you advise me alternative way – Nagaraju K Aug 21 '20 at 2:43
  • Hello @NagarajuK Please try to do re-indexing and clean & flush Magento Cache and Browser Cache and check again – Savan Patel Aug 21 '20 at 5:39

ADD this code so trailing slash remove

$hreflangUrl= https://www.example.com/contactus.html/ $result = rtrim($hreflangUrl, "/"); $result=https://www.example.com/contactus.html


Add below code in the end of your root's .htaccess file -

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R] # 
  • I have tried the redirect code as per your suggestion. But it leads to infinite redirect loop. Any other solution? – Intellect Outsource Jun 25 '18 at 5:05

You can intercept base magento 2 methods to rtrim the trailing slash. But it could lead to errors. Here is the example: https://github.com/vsevolod-tarasov/links

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.