The old, broken “inaturalist” rule was a “rewrite string” rule. The new one that replaces it is a “redirect request” rule.
My best guess as to why it broke is a feature of the old rule was available to free users but now requires a paid account. The new rule is simpler and seems to work on my free Requestly account.
If you used my old rule and want to have a working version again, please disable it and enable the new one linked above instead. Let me know if you have any issues with it.
Can we please have some update on this? This is an extremely easy feature to implement, yet not addressed for another 6 years…
As others mentioned, when people leave links to a different affiliated network, it’s just the same thing but on a different domain in nearly all cases.
Possible solutions:
1:
This works just fine. If any concerns, this replacement could be restricted to certain links, e.g. /observations/id and /taxa/id
2. Intercept the link, check that it’s the wrong affiliated domain. 2a. Then you can simply redirect the user to correct current domain if they clicked such link (however they can still copy the link and open it in a new tab with no issues, if they really wanted to!) 2b. An alternative solution would be to prompt the user to confirm whether they want to stay on the same domain (e.g. inaturalist.org and not go to inaturalist.ala.org.au)
I believe the option 2b should cover all of the concerns above.
Option 2b is similar to how some sites ask you whether you want to open a certain linked website since they can’t confirm the link can be trusted / not a malicious website. That could actually be an idea for another feature - does iNat currently simply allow to open all links posted on the website without such a warning/prompt?
Just in case here’s also an alternative barebones Tampermonkey script.
Checked and it works without issues I believe. It’s just to point to correct domain when clicking the links.
Code
// ==UserScript==
// @name iNaturalist Network Affiliation Redirect
// @namespace http://tampermonkey.net/
// @version 1.8
// @description Redirects links to other iNaturalist network sites back to the user's current iNaturalist domain, using a simplified regex for dynamic domain matching, and ignoring static.inaturalist.org.
// @author Gemini
// @match *://*.inaturalist.org/*
// @match *://*.inaturalist.ala.org.au/*
// @match *://*.inaturalist.ca/*
// @match *://*.inaturalist.mx/*
// @match *://*.inaturalist.org.pt/*
// @match *://*.inaturalist.lu/*
// @match *://*.inaturalist.se/*
// @match *://*.naturalista.uy/*
// @match *://*.biodiversity4all.org/*
// @match *://*.argentinat.org/*
// @match *://*.inaturalist.laji.fi/*
// @match *://*.inaturalist.mma.gob.cl/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Get the current hostname of the user's browser window.
// This is the domain where the user is currently browsing and is presumed to be their preferred iNaturalist network.
const currentDomain = window.location.hostname;
// Define a regular expression to match all known iNaturalist affiliate domains.
// This regex is now simplified to broadly match any subdomain for 'inaturalist.org'
// while explicitly excluding 'static.inaturalist.org'.
const iNatAffiliateDomainRegex = new RegExp(
// Matches any subdomain of 'inaturalist.org' EXCEPT 'static.inaturalist.org'
`^(?!static\\.|forum\\.)(?:.+\\.)?inaturalist\\.org$|` +
// Matches 'inaturalist.ala.org.au' (with optional 'www.')
`^(www\\.)?inaturalist\\.ala\\.org\\.au$|` +
// Matches 'inaturalist.ca', '.lu', '.nz', '.se' (with optional 'www.')
`^(www\\.)?inaturalist\\.(ca|lu|nz|se)$|` +
// Matches 'naturalista.mx', '.uy' (with optional 'www.')
`^(www\\.)?naturalista\\.(mx|uy)$|` +
// Matches 'biodiversity4all.org' (with optional 'www.')
`^(www\\.)?biodiversity4all\\.org$|` +
// Matches 'argentinat.org' (with optional 'www.')
`^(www\\.)?argentinat\\.org$|` +
// Matches 'inaturalist.laji.fi' (with optional 'www.')
`^(www\\.)?inaturalist\\.laji\\.fi$|` +
// Matches 'inaturalist.mma.gob.cl' (with optional 'www.')
`^(www\\.)?inaturalist\\.mma\\.gob\\.cl$`,
'i' // 'i' flag makes the regex case-insensitive for domain matching
);
/**
* Handles click events on the document body.
* This function uses event delegation to efficiently check if a clicked element is an anchor tag
* and if its URL points to a different iNaturalist affiliate domain.
* @param {Event} event - The DOM click event object.
*/
document.body.addEventListener('click', function(event) {
// Traverse up the DOM tree from the clicked element to find the nearest ancestor that is an <a> tag.
// This is robust for clicks on child elements within a link (e.g., an image inside an <a>).
const anchor = event.target.closest('a');
// Proceed only if an anchor element was found and it has a valid 'href' attribute.
if (anchor && anchor.href) {
try {
// Parse the anchor's href into a URL object for easy access to its components (hostname, pathname, etc.).
const clickedUrl = new URL(anchor.href);
// Check two conditions for redirection:
// 1. The clicked link's hostname must match one of the defined iNaturalist affiliate domains using the regex.
// 2. The clicked link's hostname must be different from the current page's hostname.
if (iNatAffiliateDomainRegex.test(clickedUrl.hostname) && clickedUrl.hostname !== currentDomain) {
// Prevent the browser's default navigation behavior for this link.
event.preventDefault();
// Construct a new URL. This new URL will use:
// - The protocol and hostname of the *current* page (`window.location.origin`).
// - The path, query parameters, and hash from the *original clicked link*.
// This effectively redirects the user to the same content on their current network affiliation.
const newUrl = new URL(clickedUrl.pathname + clickedUrl.search + clickedUrl.hash, window.location.origin);
// Navigate the browser to the newly constructed URL.
window.location.href = newUrl.toString();
}
} catch (e) {
// Log any errors that occur during URL parsing or redirection logic.
// This helps in debugging malformed URLs or unexpected scenarios.
console.error("iNaturalist Redirect Script: Error processing URL:", anchor.href, e);
}
}
});
// Console log to confirm that the Tampermonkey script has been loaded and is active.
console.log("iNaturalist Network Affiliation Redirect script loaded and active.");
})();
I am running into this problem when I ask people to join projects because they have it set so that observations cannot be added to projects they haven’t joined. It would be nice to link a project to people using other domains and not run into this issue.