0

I would to put a trailing slash at the end of my CMS URL, but without make redirection when it's possible : I want to put this slash when the URL is build.

In the BO, in CMS page, we can define url key, for instance "my-url". In the website, we can access to this url by : example.com/my-url or example.com/my-url/ (both work).

In CMS bloc, we can call this url with the following code : {{store url="my-url"}} or {{store url="my-url/"}}.

So, what is the most recommended ?

1 - Update all content CMS bloc and change {{store url="my-url"}} by {{store url="my-url/"}}. => but how change that in mass ?

2 - Override the url build and have this url example.com/my-url/ even if it's {{store url="my-url"}} in the bloc. => but how make this override ?

3 - Another idea ?

Thank you for your suggestions.

0

You can use only .htaccess for this

RewriteCond %{REQUEST_URI} !(/$|\.)
 RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]

And here is htaccess solution for Magento

Magento 2 - URLs trailing slash redirection

And for Magento 1 for programatic change of URL Internal links to end with a trailing slash

I didn't check this:

    public function getUrl($routePath = null,
 $routeParams = null){ 
$url = parent::getUrl($routePath, $routeParams);
 if (substr($_GET['page'], -1) !== '/') { 
$parts = explode('?', $_SERVER['REQUEST_URI'], 2); 
    $uri = 'http://example.com'.$parts[0].'/'.(isset($parts[1]) ? '?'.$parts[1] : ''); 
    header('Location: '.$uri, true, 301); exit; }
         return $url; }
  • I said I don't want to make redirection ;) And I'm on Magento 1 not 2 – Kozame Oct 24 '18 at 8:52
  • Sorry I update my answer , please read topic from link, there is also discussion about "What is the point?" – BartZalas Oct 24 '18 at 9:02
  • Err.. Here to, you make a redirection : header('Location: '.$uri, true, 301);. I really want to do that without redirection. I will try to override getUrl and see if it's possible – Kozame Oct 24 '18 at 9:26
  • Maybe export all products to csv and add slash in editor on "url_key" and import. – BartZalas Oct 24 '18 at 15:42
  • It's not products, it's CMS page, and we can't add slash in the url-key (not work for me) – Kozame Oct 25 '18 at 7:47

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.