Shallow URLs? (no hierarchy)

Permalink
Hi all

Does anyone know how I can make the canonical URL of all my C5 pages shallow so that they appear to be directly under the root domain? (rather than grouped in hierarchical subfolders)

e.g.

I want this: mysite.com/baseball-cards/
rather than this: mysite.com/baseball-products/baseball-cards/

(Imagine I have 30 products, I don't want them all located in the site root in my sitemap with my other files/products, but neatly in a "baseball products" folder - however I don't want them to indicate their position in the URL.)

I know I can create a redirect for this, but I want the shorter URL to be the canonical URL, not just a redirect to the long one.

Why do I want to do this?
1. I am convinced there is some sort of SEO value to this - something to do with the page being closer to the root domain than filed down lower in the site structure.
2. If I want to move the page around my site navigation-wise, or change "subfolder" names, my canonical URLs do not need to change (remain persistant) - v. good for maintaining links.

Has anyone done this before with c5 that can help me? I've done it with CMSMS & Wordpress in the past with htaccess/mod_rewrite - just didn't know if c5 calculates URLs in a tricky way...

Cheers!

malkau
 
TheRealSean replied on at Permalink Reply
TheRealSean
According to Mat Cutts, its a secondary objective for seo wise
http://www.youtube.com/watch?v=gRzMhlFZz9I...

as for actually doing it

you can add an alternative url on each of the pages, but These do not filter down,

ie /root/categories/products could be accessed by /root/products

but /root/categories/products/options would not inherit this to produce /root/products/options

If you are willing to go that root, you could use htaccess to the forward all the categories to go to products, I do it quite a bit but nothing as big as a products db so its normally only one or two pages.

Im using the following to create canonical links but this would need to be tweaked to use the new urls

<?php 
   $canonical = $c->getCollectionPointerID() ? Page::getByID($c->getCollectionPointerID()) : $c;
   $nh = Loader::helper('navigation');
   printf('<link rel="canonical" href="%s" />', $nh->getCollectionURL($canonical));echo "\n";
  ?>

I am going to assume there is a way to use $_SERVER['REQUEST_URI'] with some regular expression instead?, to maybe set the canonical links to the shortened url when on the categories/products pages.

Im not sure about this but maybe something like(wrapped with an if for only cat products)
$canonical = preg_replace('/([a-zA-Z-]+)\/([a-zA-Z-]+)(\/)?/i', '$2', $_SERVER['REQUEST_URI']);

again not to sure if this would work but you may be able to get the page object using Page::getByPath("/products"); if you prefer to work with the object? - (Thinking about this it should be possible grab the page object and then set the extra URL for the page, I dont know the function used? I'm afraid)

I think a challenge may also arise when you use the page selector which will use the default page url instead of your nice canonical link.
TheRealSean replied on at Permalink Reply
TheRealSean
A little bit of searching seems to bring up this
$c->addCollectionAlias($c);
http://www.concrete5.org/api/Pages/Page.html#addCollectionAlias...

and some on the forum
http://www.concrete5.org/community/forums/customizing_c5/adding-inf...


Now I dont know if this will work its all theory
<?php 
$c = Page::getByPath($_SERVER['_REQUEST_URL']);
$ncID = $c->addCollectionAlias($c);
?>
malkau replied on at Permalink Reply
malkau
Belated thanks for your replies, TRS, but as I have not coded anything in c5 before so wouldn't know where to begin with putting that code {:-)

Anyway - I've added it as a feature request here:
http://www.concrete5.org/community/forums/usage/feature-request-abi...
Maybe it'll be added to the core one day... :-)
RoyB replied on at Permalink Reply
Hey Malkau - we have the same problem and it seems like a fundamental improvement that needs to be made to the CMS - have you had a reply on your feature request?
InfiniteSandwiches replied on at Permalink Reply
I think I've found an easy solution:

http://www.concrete5.org/index.php?cID=478723...