landitus Posted February 27, 2012 Share Posted February 27, 2012 Hi all, I would like to create some short urls and remap others without affecting the PW tree. For instance, I have the following tree structure: ProductsProduct 1 Product 2 Product 3 Product 100... [*]Categories [*]Industries I would like to have the following URLs: http://site/products http://site/products/categories >>> goes to /site/categories/ http://site/products/industries >>> goes to /site/industries I've tried the redirects module, but I won't work because /site/categories/ is a valid URL already. I wouldn't want to nest Categories and Industries in the tree because I have 100 products in Products. What can I do? Should I create a proxy? Like here ? Is there a clean/preferred way? Link to comment Share on other sites More sharing options...
Soma Posted February 27, 2012 Share Posted February 27, 2012 Easiest would be to use $session->redirect(url); to redirect. Not sure what exactly you're trying to archive. Do you really want to redirect a longer url to a shorter one? Or do you want display same content within another url? Link to comment Share on other sites More sharing options...
diogo Posted February 27, 2012 Share Posted February 27, 2012 Hm... i wonder if it would be possible to add a check box on page editing to make that page being skipped on URLs... An idea for a module maybe? Link to comment Share on other sites More sharing options...
landitus Posted February 27, 2012 Author Share Posted February 27, 2012 I'm trying to Remap some URLs without affecting the Processwire tree structure. The correct URL should be http://site/products/categories but, because "products" has 100 children, I have "Categories" outside the "Products" parent. Now I want to remap /site/categories/ to http://site/products/categories Tell me if I'm making any sense Link to comment Share on other sites More sharing options...
ryan Posted February 29, 2012 Share Posted February 29, 2012 /site/templates/categories.php <?php if($input->urlSegment1) { // you'll have to enable urlSegments in your categories template $s = $sanitizer->pageName($input->urlSegment1); $category = $pages->get('/products/categories/$s/'); if($category->id) echo $category->render(); else throw new Wire404Exception(); } Let me know if this is what you were looking for? Link to comment Share on other sites More sharing options...
Soma Posted March 1, 2012 Share Posted March 1, 2012 I think landitus means the other way round. Edit: http://domain.com/products/categories >>> goes to /site/categories/ http://domain.com/products/industries >>> goes to /site/industries By "goes" to, do you mean it redirects to it? Like if you enter the long address it instead loads http://domain.com/categories/ also in the address bar? And simply show the /categories page? I think I'm not getting it still. Link to comment Share on other sites More sharing options...
yellowled Posted June 29, 2012 Share Posted June 29, 2012 $session->redirect(url); I use this (together with a URL field als the only field of a special template) for "external" links in the navigation. Works like a charm. Now the client would like these links to open in a new tab in order to keep their web site open. Any chance to do this with $session->redirect in a sensible way? Obviously, I do not want to use target="_blank". Link to comment Share on other sites More sharing options...
SiNNuT Posted June 30, 2012 Share Posted June 30, 2012 - snip - Obviously, I do not want to use target="_blank". I don't think this is a bad choice, if you want to open external links in a new tab (or window, depending on what the user's browser and settings). In html5 the "target="_blank" isn't deprecated. Link to comment Share on other sites More sharing options...
Soma Posted June 30, 2012 Share Posted June 30, 2012 There's no way to do this in php, this has to be done in html or js client side. There's nothing against using target blank in HTML5. If you don't want to, you could add rel="ext" to the links and use jquery to make them behave like you want. This technique was often used in XHTML where target blank wasn't valid. Add it using javascript $("a[rel='ext']").attr("target","_blank"); Or using only the protocol, with any link that href starts with http:// $("a[href^='http://']").bind("click", function() { window.open( $(this).attr("href"), "_blank" ); }); 1 Link to comment Share on other sites More sharing options...
yellowled Posted June 30, 2012 Share Posted June 30, 2012 This would have been my first choice since I want to open the new tab using JS anyway, however it doesn't work on those redirected links in the navigation since the href attribute of those is still a local link. The navigation is created using Markup Simple Navigation. For any reference to an external page, I have a template page-redirect.php, which contains just <?php // Internal or external redirects in primary nav if($page->redirect_url) $session->redirect($page->redirect_url); This template only has the fields title and redirect_url. So if I had a page /markup/navigation/ with the redirect_url set to http://processwire.com, the link href in the navigation markup would still be /markup/navigation/. It's redirected after the link is clicked which is why the JS solution won't work. Can I maybe add code to Markup Simple Navigation's item_tpl using template selectors? Link to comment Share on other sites More sharing options...
Soma Posted June 30, 2012 Share Posted June 30, 2012 Ah that's something different. You could try something like this: 'item_tpl' => '<a href="{redirect_url|url}">{title}</a>' Then it will take the redirect_url if it's populated. 2 Link to comment Share on other sites More sharing options...
yellowled Posted June 30, 2012 Share Posted June 30, 2012 I have said it before, I will say it again: Markup Simple Navigation rocks! Together with a JS-based redirection to a new tab, this is very close to perfect. Thanks, Soma! 1 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