in Elftronix

How to Add Trailing Slash “/” to Joomla URLs Without .htaccess

I wanted to add a slash “/” to the end of all the URLs on my install of Joomla¬†3.3.1. So that all the pages on the site would have an address like “http://www.domain.com/page/”. As default, Joomla creates URLs without the trailing slash, ex. “http://www.domain.com/page”.

  • Confirmed still working on Joomla 3.6 and beyond.

Joomla URLs with trailing slash

This is possible to achieve with .htaccess, in my case however, I could not get it to work by pasting code suggested on the web to the default Joomla htaccess.txt file.

Luckily I found another workaround here, which I prefer anyway. The htaccess method will show links as “xx/page” and simply forward them to -> “xx/page/” per request. But this added code will add the trailing slash into Joomla itself, creating clean, working ¬†URLs.

We need to edit the site.php file. Do a back up first, and open up this file with your favourite text editor:

/home/user/public_html/libraries/cms/router/site.php

Look for the line “Set query again in the URI“, for me it was line 513 and replace the code:

// Set query again in the URI
$uri->setQuery($query);
$uri->setPath($route);

with:

// Set query again in the URI
$uri->setQuery($query);
$uri->setPath($route . '/');
}

That should fix it. The downside is, that if a future update of Joomla replaces the file with a new one, and you will need to do this again.

Please, let me know if it worked for you in the comments!

Care and share, let's call it fair! -David

Twitter Button Facebook Button Google Button LinkedIn Button

Write a Comment

Comment

  1. Hello, great it works thank you very much! I have installed joomla local with xampp. But allow me this question – is it possible to get the trailing slash by joomla menu item type External URL, too? I have in my main menu 2 such menu types. For example my local domain is just yet http://localhost/en/, my external url is https://www.motorsport.com/
    By mouseover on the external url within Firefox 54 it does not show the url preview with the trailing slash in the bottom left of the browser window? All other internal urls are showing with “/” at the end in the url preview. I would be very pleased for an answer. Kind regards Karin