cb2004 Posted July 2, 2023 Share Posted July 2, 2023 I have a site that has its landing pages underneath the URL /lp/ to keep things tidy in the admin. I have had to change things along the way with different ProcessWire versions and a bug has just been discovered with Facebook links as they add a variable to the URL. What is the best approach for the latest version? I am pretty sure you can make the names of certain templates unique so that would be my first step, and then I am thinking of plugging into ProcessPageView::pageNotFound Cheers all. Link to comment Share on other sites More sharing options...
cwsoft Posted July 2, 2023 Share Posted July 2, 2023 Hi, what have you already tried? Not really understand your actual issue. So you have a landing page under path /lp/ and then I am lost? What updates have caused which problem? What do you want to achieve, what code are you using now, whats your PW version used … Link to comment Share on other sites More sharing options...
cb2004 Posted July 2, 2023 Author Share Posted July 2, 2023 Hi @cwsoft, sorry you are right, is was a very vague Sunday post whilst trying to spend time with the family. So basically there could be /lp/offer1/ but if I went to /offer1/ I would like it to redirect to the correct page, as this is a shorter URL for printed material. This is what we have currently in _init.php <?php namespace ProcessWire; $wire->addHookBefore('ProcessPageView::pageNotFound', function($e) { $name = str_replace('/', '', $_SERVER['REQUEST_URI']); $count = wire('pages')->count("name=$name, include=hidden"); if($count) { $id = wire('pages')->find("name=$name, include=hidden"); $url = wire('pages')->get("$id")->url; wire('session')->redirect($url); } }); Cheers Link to comment Share on other sites More sharing options...
flydev Posted July 5, 2023 Share Posted July 5, 2023 Hi, I think you can make it easier without dealing with 404 hook. You should give a read at this blog post about new URL hooks: https://processwire.com/blog/posts/pw-3.0.173/#new-type-of-hook-for-handling-request-urls 2 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