How to remove parent pages from url
Permalink
I think I've found a simple and easy way to remove the parent portion of any given page url. Simply override the page model by saving this snippet as a file called models/page.php:
This will only work for pages which are added after saving the file above. Its really just commenting out the one line that adds the parent prefix to any given page url.
This feature was requested from the following threads:
http://www.concrete5.org/community/forums/customizing_c5/shallow-ur...
http://www.concrete5.org/community/forums/usage/feature-request-abi...
http://www.concrete5.org/community/forums/customizing_c5/changing-c...
http://www.concrete5.org/community/forums/customizing_c5/how-to-rem...
This was built from version 5.6.1.2. Please test and let me know if anybody encounters any problems. I think this should be merged into the main branch of concrete5. Page urls should not be intrinsically tied to navigation. It can easily have a negative effect on SEO. Full control over the entire url is important.
Thanks
<?php defined('C5_EXECUTE') or die("Access Denied."); class Page extends Concrete5_Model_Page { function rescanCollectionPath($retainOldPagePath = false) { if ($this->cParentID > 0) { $db = Loader::db(); // first, we grab the path of the parent, if such a thing exists, for our prefix $q = "select PagePaths.cPath as cPathParent from PagePaths left join Pages on (Pages.cParentID = PagePaths.cID and PagePaths.ppIsCanonical = 1) where Pages.cID = '{$this->cID}'"; $cPath = ""; //$db->getOne($q); Removes parents from url slug // Now we perform the collection path function on the current cID $np = $this->rescanCollectionPathIndividual($this->cID, $cPath, $retainOldPagePath); $this->cPath = $np; // Now we start with the recursive collection path scanning, armed with our prefix (from the level above what we're scanning) if ($np) { $this->rescanCollectionPathChildren($this->cID, $np);
Viewing 15 lines of 19 lines. View entire code block.
This will only work for pages which are added after saving the file above. Its really just commenting out the one line that adds the parent prefix to any given page url.
This feature was requested from the following threads:
http://www.concrete5.org/community/forums/customizing_c5/shallow-ur...
http://www.concrete5.org/community/forums/usage/feature-request-abi...
http://www.concrete5.org/community/forums/customizing_c5/changing-c...
http://www.concrete5.org/community/forums/customizing_c5/how-to-rem...
This was built from version 5.6.1.2. Please test and let me know if anybody encounters any problems. I think this should be merged into the main branch of concrete5. Page urls should not be intrinsically tied to navigation. It can easily have a negative effect on SEO. Full control over the entire url is important.
Thanks
It detected that the product page already existed and so it added "1" to the path. Unless I'm missing something, you must have another page with the same name...its up to you to name each page uniquely.
That's my point. Common pages such as 'Products' would need unique names. Is that something you want to foist on clients?
Its a business decision I suppose, but I find it far more preferable to having the url locked in place. I often have sites with categories for navigation (sometimes a couple levels deep) and I don't want those categories in the url. Typically subpages look more like products/shoes/ and products/purses/, in which case the resulting purses/ and shoes/ urls would be fine.
I suppose the best solution would be to include the parent page in the url, but to have the entire url be editable regardless. I haven't found a way to do this though.
does not work , i added the page 'root/models/page.php' an pasted that code in, did nit fix my url's , i also tryed adding more pages but they also added parent pages in the slug , if you can give me more pointers or if you can tell me what wrong thing i did it will be much appreciated. thanks a lot.
im using concrete5.6.2.1
First make sure you have your 'Override cache' turned off in 'Dashboard->System and Settings->Cache and Speed Settings'
i did that , and now when i add the page.php the whole site does not load for some reason , any suggestion ? is the code above the entire code i need to use?
I have just completed some work for a site that required such urls. A consistent and reliable solution is much more involved than the above code. It is not something I would recommend.
can you share with me what you did for your website?
my client needs this as well
my client needs this as well
Please PM me offline with a direct email and we can talk commercial terms 'in confidence'. Its not something I can post on an open forum or even via PM.
Did you solve this in the end?
www.www.domain.com/shoes/products...
www.www.domain.com/purses/products...
Using your modified page.php, I now get:
http://www.domain.com/products
http://www.doamin.com/products1
Is that a good thing?