Jump to content

Jumplinks


Mike Rockett

Recommended Posts

57 minutes ago, Mike Rockett said:

@teppo - in regards to Jumplinks 2 and composer support: the module utilises several composer packages, which at present are kept in the vendor directory of the module, part of source control. Just to be 100% sure, if I were to drop this from source control, this would force users to install via composer? If so, I'd need to leave it in there, unless you know of another way ?

45 minutes ago, Mike Rockett said:

@wbmnfktr - Hence why I'm needing some more info – not sure if any additional composer support has been added. Would be great if I could trigger an install during module install from the UI. ?

Sorry, I've got nothing for this. At this point my suggestion would be to keep those packages in the repository. It's the only way that works seamlessly with the module installer in Admin, and I believe it makes more sense for your module than any of the alternatives I can think of. Anything else would reduce your potential user base significantly.

I've gone the other way with some of my projects, but those have mainly been site profiles, so the context is quite different. While I agree that a native Composer installation integration could be nice, we're not quite there yet — at this point requiring Composer may make sense for hard-core developer-oriented projects, not much else.

57 minutes ago, Mike Rockett said:

On the topic of dependencies, I'm feeling inclined to push the minimum PHP version to the one that still has active security support, which at this point is PHP 7.1.

Go for it! I've been putting out PHP 7.1+ content for a while now, and so far no complaints.

It's perhaps worth noting that PHP 7.1 is well on its way to being obsolete as well: it's already past the active support phase, and in just over two months it will stop receiving security updates. While certain organisations may backport security fixes for 7.1 for a while after that, officially its really close to the end of its lifespan. Folks should be already using (or at the very least actively updating to) 7.2 – or preferably 7.3 ?

56 minutes ago, Mike Rockett said:

I'd also like to drop support for ProcessWire 2.8. Any objections?

Again: go for it ?

I don't think that this will affect a particularly large portion of users (last time I polled this was in 2017, but even back then ~55% of those responding were already on 3.0), 2.8 itself hasn't been updated for almost three years now, and users of legacy versions can always keep using one of the solutions that work for said legacy setups.

Link to comment
Share on other sites

5 minutes ago, teppo said:

Sorry, I've got nothing for this. At this point my suggestion would be to keep those packages in the repository. It's the only way that works seamlessly with the module installer in Admin, and I believe it makes more sense for your module than any of the alternatives I can think of. Anything else would reduce your potential user base significantly.

Ah ok, thanks for the clarification there. Guess the optimist in me was hanging around ?

6 minutes ago, teppo said:

Go for it! I've been putting out PHP 7.1+ content for a while now, and so far no complaints.

Good to know - thanks!

Link to comment
Share on other sites

  • 2 weeks later...
On 9/15/2019 at 12:07 PM, Mike Rockett said:

These columns are sorted in 1.5.56. However, instead of text, I've gone with varchar(512), which should be more than long enough. ?

Thanks for this Mike. 

Not sure if 512 is long enough. There isn't any limitations for user agent length (other than server limit for headers) and if request_uri means uri that user were redirected - then few pointers for uri lengths:

Quote

The HTTP protocol does not place any a priori limit on the length of a URI

and 

Quote

Extremely long URLs are usually a mistake. URLs over 2,000 characters will not work in the most popular web browsers. 

https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers

So if you want to limit these at the database level, then you should clip values also to that length.

Link to comment
Share on other sites

  • 2 weeks later...

Hello, I'm having a really strange issue with this plugin. I using the latest version of PW and all modules. I have a blog (using ProcessBlog & MarkupBlog) and removed a bunch of old posts, I wanted to redirect them to the main blog page (domain.com/blog/). For whatever reason, if I try to register a new jumplink and it has "blog/" in the source (domain.com/blog/posts/some-post/), the redirect doesn't work. I thought maybe I had a problem with one of the existing blog post redirects, so I removed all jumplinks with "blog/" in them and it's still happening. I've tried disabling my other modules, installed Tracy Debugger (no issues), uninstalled Jumplinks and re-installed....no luck. I turned on debug mode in Jumplinks and if I open the source (original) URL in a browser, the debug screen isn't shown. If I register a new jumplink and don't have "blog/" in the source, everything works fine. Even stranger, if I try to visit one of the source URLs with "blog/" in it, the content for the intended page is displayed, but the address bar still shows the source (original) url. I've been pulling my hair out all day and have run out of ideas, please help! ?

Link to comment
Share on other sites

Ok. I don't know if there is anything modified in your site or a difference in our installed modules so this might not work but I just installed ProcessBlog & MarkupBlog and of course the latest Jumplinks module.

I unpublished the example post, opened it in a private window where a 404 showed up.
I looked into the Jumplinks 404 monitor and found the request.
I opened that entry, created a new jumplink from it and visited the URL in a private window again and... it worked.

ProcessWire 3.0.123 the other modules straight from modules.processwire.com.

2019-10-10-230022_812x599_scrot.png.f40dc5d362b40a4e8a1874da9df3a352.png

Link to comment
Share on other sites

4 minutes ago, wbmnfktr said:

I opened that entry, created a new jumplink from it and visited the URL in a private window again and... it worked.

Yeah, it's weird... I've been using this module for a couple years and never had a problem. The redirects do still work on any source url that don't have "blog/" in them. I'm stumped. Here are the modules I've added in case it helps, all are the latest versions.

AdminOnSteroids
AutoSmush
BlogPublishDate
FieldtypeStarRating
FormBuilder
GoogleClientAPI
InputfieldFormBuilderFile
InputfieldStarRating
MarkupBlog
MarkupSimpleNavigation
MarkupSitemapXML
ProCache
ProcessBlog
ProcessDatabaseBackups
ProcessFormBuilder
ProcessJumplinks
ProcessProCache
ProcessTracyAdminer
ProcessWireUpgrade
ProcessWireUpgradeCheck
TracyDebugger
WireMailGmail

Link to comment
Share on other sites

@Ben Sayers This could indicate that something's wrong with your blog setup. To clarify, are you deleting posts or un-publishing them? Either way, whatever is going on here is preventing the 404 event from kicking in, which means Jumplinks has nothing to do. When it comes to common patterns like this (ie, "blog/*"), the only things that come to mind are urlSegments and custom htaccess directives, both of which I suspect are not the case for you. Worst case, I would try reproducing on a fresh install.

On a side note: I don't know ProCache very well, but could it possibly be that?

Link to comment
Share on other sites

@apeisa I think I'll take the trimming option here, for now. I have been doing incremental work on JL2 in my very short-lived spare-time, and will be using a text column for referrers in the hits table. I'm deciding whether or not the 404 monitor should still be a separate module like I'd originally intended - still makes more sense to me, but either way, the same column type will be used there.

Link to comment
Share on other sites

On 10/11/2019 at 12:01 AM, Mike Rockett said:

To clarify, are you deleting posts or un-publishing them? When it comes to common patterns like this (ie, "blog/*"), the only things that come to mind are urlSegments and custom htaccess directives

I deleted the posts. I do use URL segments for the AMP versions of my pages but I'm not creating any jumplinks for those (yet). The only htaccess directives I added are for alternate domain names to redirect them to our primary domain. Like this:

RewriteCond %{HTTP_HOST} ^secondarydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.secondarydomain.com$
RewriteRule (.*)$ https://www.primarydomain.com/$1 [R=301,L]

 

Link to comment
Share on other sites

  • 2 weeks later...

Hi everyone,

I haven't really used this module much before, but just came across something that I thought should work, but it doesn't seem to.

This works:

image.png.cd1e601e66d48a4d84d428134a11a7c7.png

But this doesn't:

image.png.b6ed0a19fcb903177ea12609bedfa0cb.png

which of course means that if someone changes the name of the "buy-now" to something else, not only do I need to add a new jumplink from "buy-now" to the new name, but I also need to remember to change the destination for the initial linking from "/subscribe" to the path of the renamed page. Is there any reason the "page:1495" format can't also work when using wildcards?

Just in case it's not clear, {all} represents a PW url segment.

Thanks for any thoughts.

OT, but I was actually a little surprised that the core PagePathHistory module doesn't try to handle paths with urlsegments - I know it's not simple, but I thought it could try to strip back a segment at a time to try to find the actual page and redirect to the stored ID.

Link to comment
Share on other sites

@Ben Sayers, if you're still having problems and just need a solution to get the redirects working you could hook ProcessPageView::pageNotFound in /site/init.php

$wire->addHookBefore('ProcessPageView::pageNotFound', function(HookEvent $event) {
	$url = $event->arguments(1);
	// The old URLs you want to redirect from (relative to site root)
	$redirects = [
		'/blog/foo/',
		'/blog/bar/',
	];
	if(in_array($url, $redirects)) {
		// Get the blog landing page however suits
		$blog_page = $this->wire('pages')->get('template=blog');
		// Redirect to blog landing page
		$this->wire('session')->redirect($blog_page->url);
	}
});

 

Link to comment
Share on other sites

7 hours ago, adrian said:

OT, but I was actually a little surprised that the core PagePathHistory module doesn't try to handle paths with urlsegments - I know it's not simple, but I thought it could try to strip back a segment at a time to try to find the actual page and redirect to the stored ID.

Equally OT, but it sounds like this could result in unwanted consequences: PagePathHistory hooks into ProcessPageView::pageNotFound, so initially it only knows that a Page is missing. If it doesn't have a record for that exact URL, the most straightforward approach for supporting URL segments (as you've suggested) would mean that it needs to recurse through the path and see if it can find a record for a partial match for a Page that has URL segments enabled (which is getting somewhat complex, and creates a bit of overhead), and – since ProcessWire can't really know for sure which segments are available, let alone were available in the past – it would probably just have to assume that anything goes.

In addition to the overhead and general unreliability, it also sounds like this could create redirects for URLs that should just throw a 404, and we'd also have some new questions: is it enough to check if the target page currently has URL segments active, or should we assume that this may have changed as well? What about the redirect – is it enough (i.e. helpful) to redirect to the parent page, or should it attempt to redirect to an URL segment on that page? If we do that and it fails, what next?

All in all I can see a number of potential gotchas here, so not supporting URL segments seems like a reasonable decision. They are "virtual paths", and PagePathHistory is for real paths ?

  • Like 1
Link to comment
Share on other sites

Thanks for your thoughts @teppo - I agree it's not a simple problem to solve and that there are some gotchas for sure. However I feel like if some assumptions are made, it could be made to be functional.

Firstly, if only supported first level pages (those directly under home), we could simply strip off everything after the second forward slash and assume those are urlsegments and simply find the page that matches the ID of the page whose name was changed and then re-append all those segments as they were in the original URL. I know this wouldn't solve the problem for all setups but I bet it would handle most. I think this discussion should be continued here: https://github.com/processwire/processwire-requests/issues/338

  • Like 1
Link to comment
Share on other sites

On 10/22/2019 at 6:18 PM, Robin S said:

@Ben Sayers, if you're still having problems and just need a solution to get the redirects working you could hook ProcessPageView::pageNotFound in /site/init.php


$wire->addHookBefore('ProcessPageView::pageNotFound', function(HookEvent $event) {
	$url = $event->arguments(1);
	// The old URLs you want to redirect from (relative to site root)
	$redirects = [
		'/blog/foo/',
		'/blog/bar/',
	];
	if(in_array($url, $redirects)) {
		// Get the blog landing page however suits
		$blog_page = $this->wire('pages')->get('template=blog');
		// Redirect to blog landing page
		$this->wire('session')->redirect($blog_page->url);
	}
});

 

Hi Robin, thanks for the advice! I tried adding this to init.php (using my real posts URLs of course) but I get the same result as when I try to add them using Jumplinks. If I load one of the URLs in my browser, I see the blog landing page but the URL is still the old one (/blog/post-title/ instead of just /blog/. If I try to redirect a page using this code that isn't a blog post, it doesn't work, I just get a 404. 

Link to comment
Share on other sites

7 hours ago, Ben Sayers said:

If I load one of the URLs in my browser, I see the blog landing page but the URL is still the old one (/blog/post-title/ instead of just /blog/.

Sounds like something is interfering before ProcessPageView::pageNotFound can execute. You can check by using Tracy Debugger to dump $url inside the hook and see if the hook is firing or not. If not then it might be caused be something in .htaccess or in Jumplinks. To check you could copy the site to your local machine, replace .htaccess with a clean copy and uninstall Jumplinks - whether it's worth the trouble depends on how important it is to you to get those redirects working.

Link to comment
Share on other sites

On 10/24/2019 at 6:07 PM, Robin S said:

You can check by using Tracy Debugger to dump $url inside the hook and see if the hook is firing or not.

Hi Robin, I'm not sure how to do that... Can you elaborate? I enabled Tracy Debugger but don't see any errors when I visit one of the blog post URLs that should be redirected. Thanks for your help!

Link to comment
Share on other sites

@Ben Sayers, you can use bd() to dump the $url variable in the hook.

$wire->addHookBefore('ProcessPageView::pageNotFound', function(HookEvent $event) {
	$url = $event->arguments(1);
	// Dump $url to the Tracy debug bar
	bd($url, 'url');
	// The old URLs you want to redirect from (relative to site root)
	$redirects = [
		'/blog/foo/',
		'/blog/bar/',
	];
	if(in_array($url, $redirects)) {
		// Get the blog landing page however suits
		$blog_page = $this->wire('pages')->get('template=blog');
		// Redirect to blog landing page
		$this->wire('session')->redirect($blog_page->url);
	}
});

When you visit a URL that does not match any page then you'll see the $url variable dumped via the Tracy debug bar. Tracy docs are here: https://adrianbj.github.io/TracyDebugger/#/debug-methods?id=bardump

2019-10-26_114634.png.e62d056ac70a8eee91048a7ea7d99ff1.png

Enter some random letters in the URL to confirm that the hook is firing and you can see the dump. Then try one of your old blog post URLs. If you don't see any dump then the hook is not firing, in this case because ProcessPageView::pageNotFound() is not executing. In which case you have something interfering before PW can attempt to render the page requested in the URL - so probably due to an .htaccess rewrite or something caused by Jumplinks (or another module or hook if you have anything else that affects URLs).

Link to comment
Share on other sites

@adrian Page identifiers were never intended to be used as part of a destination. These identifiers use the full, absolute URL of the page being identified. Perhaps destination selectors could come in handy here? Haven't ever tried it this way before, but I imagine redirecting subscribe/{all} to [[1495]]{all} (or [[1495]]/{all}} if trailing slashes are turned off) would work. Anything inside the square braces is passed to pages->get and replaced with page->url, which is why I believe this will work.

  • Like 1
Link to comment
Share on other sites

22 hours ago, Robin S said:

@Ben Sayers, you can use bd() to dump the $url variable in the hook.

When you visit a URL that does not match any page then you'll see the $url variable dumped via the Tracy debug bar. Tracy docs are here: https://adrianbj.github.io/TracyDebugger/#/debug-methods?id=bardump

Enter some random letters in the URL to confirm that the hook is firing and you can see the dump. Then try one of your old blog post URLs. If you don't see any dump then the hook is not firing, in this case because ProcessPageView::pageNotFound() is not executing. In which case you have something interfering before PW can attempt to render the page requested in the URL - so probably due to an .htaccess rewrite or something caused by Jumplinks (or another module or hook if you have anything else that affects URLs).

Hi Robin, I tried this but I don't see anything being dumped via the Tracy Debug bar. Even when using random letters,  I see my 404 page but nothing in the dump. If I load one of the blog posts that should be redirecting, I see the the Blog landing page content but it still shows the old URL (the same thing that happens when I try to use Jumplinks to redirect blog posts). Your code is the only thing I have in my init.php file except for my _func.php include. The only edits to my .htaccess file are those required by ProCache (gzip & manual directives). I do use url segments for the amp versions of my pages but I haven't created an amp version of my blog pages yet so I'm stumped on what can be causing this. I'm using the latest versions of PW and all modules.

Link to comment
Share on other sites

18 minutes ago, Ben Sayers said:

This is the only thing I have in my init.php file except for my _func.php include.

I think you might be working with the wrong init.php - you'll see in my earlier post that the hook needs to go in /site/init.php. Along with /site/ready.php this is one of the places that hook code is commonly added to. You can create either/both of these files if they don't exist. More info in this blog post: https://processwire.com/blog/posts/processwire-2.6.7-core-updates-and-more/#new-core-files-for-site-hooks

Turn off ProCache while you are investigating the issue to make sure it isn't contributing to the problem.

 

Link to comment
Share on other sites

@Ben Sayers

I'm by no means an expert on hooks, but I usually put hooks in ready.php, not init.php. Maybe that's the reason why your hook is not even firing.

https://processwire.com/docs/modules/hooks/#where-should-i-define-my-hook

Quote

The ready.php file is called when the API is ready, but before page rendering has begun. While the init.php file is called during ProcessWire initialization (before the API is fully ready).

 

Link to comment
Share on other sites

Sorry Robin, you were right, I was working in /site/templates/init.php so I removed the code from that file and placed it in a new file at /site/init.php but I get the same result (nothing happens). How does /site/init.php get called? I don't have a /site/ready.php file. I disabled ProCache when this all started, it doesn't have any effect when it's on though (it's currently off). Really appreciate your help, I don't understand why the Jumplinks work with any page that doesn't contain "blog/".

Edit: I had the file named incorrectly (/site/_init.php) so I removed the underscore in the name and now I can see the dump is working but only for URLs that don't have "blog/" in them and I'm not redirected to the blog landing page, I get a 404. If I try a link with "blog/" in it, I see the blog landing page but the URL is still the old one instead of domain.com/blog/.

Edited by Ben Sayers
Small update regarding /site/init.php
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...