How do I stop autonav adding a trailing slash to my urls?
Permalink
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!
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!
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.
By the way, are you using Pretty URLs? Just curious.
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.
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.
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):
...and just ABOVE that line, add this new line:
if ($c->getCollectionID() == $_c->getCollectionID()) {
...and just ABOVE that line, add this new line:
$pageLink = rtrim($pageLink, '/'); //remove trailing slashes for SEO purposes
Fantastic thanks very much!!!
I had looked at using rtrim in the .htaccess
I had looked at using rtrim in the .htaccess
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.
I have just been looking in view and controller files but I can't identify where I would insert rtrim.
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)?
(Or if you've already created a custom template for it, paste in the contents of that file)?
Jordanlev thank you very much for coming back to me.
I am using the latest C5 here is concrete/block/page_list/view.php
I am using the latest C5 here is concrete/block/page_list/view.php
<?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"> <?php for ($i = 0; $i < count($cArray); $i++ ) { $cobj = $cArray[$i]; $target = $cobj->getAttribute('nav_target'); if ($cobj->getCollectionPointerExternalLink() != '') { if ($cobj->openCollectionPointerExternalLinkInNewWindow()) { $target = "_blank";
Viewing 15 lines of 48 lines. View entire code block.
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)
(Or just tell me what folders you see listed in SITEROOT/updates)
Yep update folder 5.5.2.1 here you go...
<?php 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();
Viewing 15 lines of 67 lines. View entire code block.
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:
...insert a new line and put this code there:
$url = $nh->getLinkToCollection($page);
...insert a new line and put this code there:
$url = rtrim($url, '/'); //remove trailing slashes for SEO purposes
You are a ledgend kind sir!
Would this really require a 301? In other words, would this really appear as a completely different page than without the trailing slash?
According to Google Webmaster tools and our SEO company yes it does.
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..