I'm trying to use mod_substitute in .htaccess to match any external URLs that do not match the current domain, and redirect them to a specific page within the website:
AddOutputFilterByType INFLATE;SUBSTITUTE;DEFLATE text/html text/plain text/xml
Substitute "s|(<a\s[^>]*)href=\"http(.?)://([^/]+)(?<!www\.mywebsite\.dev)/[^\"]*\"|$1href=\"http://www.mywebsite.dev/exit/?redirect=http$2://$3\"|i"
It ends up changing my links to this:
www.mywebsite.dev/exit/?redirect=www.mywebsite.dev
The closest I came in searching is this: How to rewrite external links (redirect to an Exit Page) with Apache mod_rewrite or RewriteCond? but the example regex creates a server error in .htaccess.