1

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.

7ochem
7,61516 gold badges54 silver badges82 bronze badges
asked Jun 23, 2018 at 6:50
1
  • 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

6

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

example:

<a href="{{store direct_url='contact-us'}}">Contact</a>
answered Sep 25, 2019 at 7:24
2
  • 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
1

ADD this code so trailing slash remove

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

answered Sep 23, 2019 at 7:05
0

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

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /1ドル [L,R] # 
Rohan Hapani
17.6k9 gold badges57 silver badges99 bronze badges
answered Jun 23, 2018 at 11:02
2
  • 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 Commented Dec 1, 2022 at 14:36
0

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

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.