How do I stop autonav adding a trailing slash to my urls?

Good afternoon Chaps / Chapettes

This is my first post in the support forums (I am a Joomla convert) and so far I am loving it! I have created my own custom theme and built the majority of my new site and everything is well except for an SEO issue.

I can't for the life of me work out how I stop the autonav adding a trailing slash to my URLs.

I have had a good search through the forums and online else where but all fixes seem to be out of date as I am using the latest version.

If someone could point me to the right .php file and let me know what I need to edit I would be most grateful.

Mods: I hope this is the right section if not sorry in advance!

View Replies: View Best Answer
Remo replied on at Permalink Reply
Why would you want to do this? Who says that there shouldn't be a slash at the end?

I only see one reason why there should be one: If you don't have you, you force your webserver to run an additional redirect which isn't necessary. This slows down your site, it's quite likely that you won't notice that as such a request doesn't take a lot of time but if you have a big site it better keep that slash where it is..
nkennel replied on at Permalink Reply
I agree with Remo. In this case, your URLs point to directories indicated by the trailing slash. Only files (e.g. index.php) do not have trailing slashes. When you link to a directory name without a trailing slash, the server looks for a file named "my-directory" first and when it doesn't find it, it has to redirect to the default file in "my-directory/" (where you intended it to go in the first place). The slash is a fundamental filesystem thing and shouldn't be changed.

By the way, are you using Pretty URLs? Just curious.
ross111 replied on at Permalink Reply
Hi guys thanks for replying.

The reason I was looking to do this is I am rebuilding my businesses website and the pages are indexed without the "/" so I just wanted to keep it the same.

The SEO company my company uses has reviewed the development site and flagged this as an issue and advised me to remove it.

I could go down the 301 redirect route or start messing about with conical tags but I really don't want to risk messing up our rankings in a very competitve market that has taken us time and money to achieve.

I am using pretty links.

Thanks again for any help.
jordanlev replied on at Permalink Best Answer Reply
You could make a custom template for the autonav block -- on your server, copy SITEROOT/concrete/blocks/autonav/view.php to SITEROOT/blocks/autonav/view.php (you'll need to create that SITEROOT/blocks/autonav/ directory). Then edit that new copy of the file and find this line (should be around line #67):
if ($c->getCollectionID() == $_c->getCollectionID()) {

...and just ABOVE that line, add this new line:
$pageLink = rtrim($pageLink, '/'); //remove trailing slashes for SEO purposes
ross111 replied on at Permalink Reply
Fantastic thanks very much!!!

I had looked at using rtrim in the .htaccess
ross111 replied on at Permalink Reply
You have already been so helpful but could I ask how would I implement this in the page list?

I have just been looking in view and controller files but I can't identify where I would insert rtrim.
jordanlev replied on at Permalink Reply
Depends on which version of C5 you're using (the page list template changed back in 5.5. I think). Can you paste into the forum post here the contents of your SITEROOT/concrete/blocks/page_list/view.php file?
(Or if you've already created a custom template for it, paste in the contents of that file)?
ross111 replied on at Permalink Reply
Jordanlev thank you very much for coming back to me.

I am using the latest C5 here is concrete/block/page_list/view.php

   defined('C5_EXECUTE') or die("Access Denied.");
   $textHelper = Loader::helper("text"); 
   // now that we're in the specialized content file for this block type, 
   // we'll include this block type's class, and pass the block to it, and get
   // the content
   if (count($cArray) > 0) { ?>
   <div class="ccm-page-list">
   for ($i = 0; $i < count($cArray); $i++ ) {
      $cobj = $cArray[$i]; 
      $target = $cobj->getAttribute('nav_target');
      if ($cobj->getCollectionPointerExternalLink() != '') {
         if ($cobj->openCollectionPointerExternalLinkInNewWindow()) {
            $target = "_blank";
jordanlev replied on at Permalink Reply
Hmm... that is the older, messier code. Perhaps you started this site last year and have since upgraded it? If so, I gave you the wrong instructions before -- instead you want to look in SITEROOT/updates/concrete5.5.2.1/blocks/page_list/view

(Or just tell me what folders you see listed in SITEROOT/updates)
ross111 replied on at Permalink Reply
Yep update folder here you go...

defined('C5_EXECUTE') or die("Access Denied.");
$rssUrl = $showRss ? $controller->getRssUrl($b) : '';
$th = Loader::helper('text');
//$ih = Loader::helper('image'); //<--uncomment this line if displaying image attributes (see below)
//Note that $nh (navigation helper) is already loaded for us by the controller (for legacy reasons)
<div class="ccm-page-list">
   <?php  foreach ($pages as $page):
      // Prepare data for each page being listed...
      $title = $th->entities($page->getCollectionName());
      $url = $nh->getLinkToCollection($page);
      $target = ($page->getCollectionPointerExternalLink() != '' && $page->openCollectionPointerExternalLinkInNewWindow()) ? '_blank' : $page->getAttribute('nav_target');
      $target = empty($target) ? '_self' : $target;
      $description = $page->getCollectionDescription();
jordanlev replied on at Permalink Reply
Okay, copy that file (SITEROOT/updates/concrete5.5.2.1/blocks/page_list/view.php) to SITEROOT/blocks/page_list/view.php, then edit the new copy of the file, and below this line:
$url = $nh->getLinkToCollection($page);

...insert a new line and put this code there:
$url = rtrim($url, '/'); //remove trailing slashes for SEO purposes
ross111 replied on at Permalink Reply
You are a ledgend kind sir!
bw1 replied on at Permalink Reply
Would this really require a 301? In other words, would this really appear as a completely different page than without the trailing slash?
ross111 replied on at Permalink Reply
According to Google Webmaster tools and our SEO company yes it does.