0

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.

alkah3st
  • 25
  • 1
  • 8
  • whats the desired output? What's the input? – Paz Oct 05 '17 at 22:35
  • So for example, http://bob.com doesn't match the current domain (mywebsite.com), so it should do: http://mywebsite.com/exit/?redirect=http://bob.com. I've got it replacing URLs in the output, it just doesn't append the domain it's redirecting correctly. – alkah3st Oct 05 '17 at 22:36

0 Answers0