Cesco Posted September 8, 2021 Share Posted September 8, 2021 Hi i need to insert many pages (over 300) to my website. This pages are buildings and i want to organize them like children inside a parent page. Example: buildings |_ building 1 |_ building 2 .... So i want that url of this pages are not "https://.... /buildings/building-1" but "https:// .... /building-1" I don't want to use rewrite because i think it not a good solution about SEO. Can i strip parent url before ? Thanks Francesco Link to comment Share on other sites More sharing options...
Jan Romero Posted September 8, 2021 Share Posted September 8, 2021 Well, you’re going to have to fight ProcessWire at least a little bit to do something like this. PW makes it easy for you to make the pages accessible at example.com/building-1 by using UrlSegments or the new PathHooks, but the page will still have the path /buildings/building-1 internally, and every time you use $page->url or $page->httpUrl, you’ll get the “real” path (according to the page tree). So it depends on how far you want to go. If you just want buildings to be accessible as though they were somewhere else in the page tree, while also being accessible at their “real” path, you just use one of the two techniques I linked above and you’re done. You still have to watch out for pages whose actual path collides with the “shortcuts”, but it’s probably not going to be a problem unless you have buildings called “contact-us” or something ? If you want to completely hide the buildings’ real urls, it gets more complicated. You might throw Wire404Exceptions or simply have no template file associated with the building template (although that will lead to other problems, like I believe it will make $page->viewable always return false). Also may need to find a way to generate your “fake” paths and use them instead of the usual $page->url everywhere (e.g. for the canonical tag, sitemaps, every time you link to a building...). If your buildings use UrlSegments or have children themselves, more problems arise. It may be worthwhile to have all buildings be children of the home page and build a way to deal with the crowded page tree in the Admin instead. Link to comment Share on other sites More sharing options...
Cesco Posted September 8, 2021 Author Share Posted September 8, 2021 Thanks @Jan Romero for your answer. My goal is to have the url of buildings like children of home page, so $page->url must return "shortcut" path. I think your last idea , all the build under home page and a flag to filter them on a page tab (?), is the best solution, if need i can create children and path still correct. Is there any module to make it or i must create new one? Thanks Link to comment Share on other sites More sharing options...
Jan Romero Posted September 8, 2021 Share Posted September 8, 2021 I haven’t used it yet myself, but there appears to be a module for this exact purpose by @Robin S : Link to comment Share on other sites More sharing options...
BitPoet Posted September 8, 2021 Share Posted September 8, 2021 The topic comes up regularly, so there's already a ton of information in the forum. If url segments for the building template aren't needed, this solution should cover the requirements: 2 Link to comment Share on other sites More sharing options...
Zeka Posted September 8, 2021 Share Posted September 8, 2021 There some usefull examples if you are in ML setup 1 Link to comment Share on other sites More sharing options...
Cesco Posted September 9, 2021 Author Share Posted September 9, 2021 17 hours ago, BitPoet said: The topic comes up regularly, so there's already a ton of information in the forum. If url segments for the building template aren't needed, this solution should cover the requirements: Tnx @BitPoet i think this is the solution ! Link to comment Share on other sites More sharing options...
diogo Posted September 9, 2021 Share Posted September 9, 2021 (edited) Just want to point out that you can also do this with the new URL hooks https://processwire.com/blog/posts/pw-3.0.173/#introducing-url-path-hooks I can't test it now, but something like this should work (not tested!): $wire->addHook('/{building}', function($event) { $name = $event->sanitizer->pageName($event->arguments("building")); $building = $event->pages->findOne("parent=/buildings/, name=$name"); if($building->viewable()) return $building; }); Edited September 9, 2021 by diogo corrected the code + added sanitizer 4 Link to comment Share on other sites More sharing options...
Cesco Posted September 10, 2021 Author Share Posted September 10, 2021 On 9/9/2021 at 10:07 AM, diogo said: Just want to point out that you can also do this with the new URL hooks https://processwire.com/blog/posts/pw-3.0.173/#introducing-url-path-hooks I can't test it now, but something like this should work (not tested!): $wire->addHook('/{building}', function($event) { $name = $event->sanitizer->pageName($event->arguments("building")); $building = $event->pages->findOne("parent=/buildings/, name=$name"); if($building->viewable()) return $building; }); Interesting solutions, i try url match works but it redirect to complete path instead of return content Interesting solution. I've tried it, but instead of showing the content of the page in the url I'm at, it redirect to the full url ? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now