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? Commented Aug 21, 2020 at 2:44

4 Answers 4


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 Commented Aug 21, 2020 at 2:43
  • Hello @NagarajuK Please try to do re-indexing and clean & flush Magento Cache and Browser Cache and check again Commented Aug 21, 2020 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] # 
  • 1
    I have tried the redirect code as per your suggestion. But it leads to infinite redirect loop. Any other solution? Commented Jun 25, 2018 at 5:05
  • This will cause redirect loop on admin panel
    – Andy
    Commented Dec 1, 2022 at 14:36

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 and acknowledge you have read our privacy policy.

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