How to rewrite external links (redirect to an Exit Page) with Apache mod_rewrite or RewriteCond?
I honestly spent hours trying to find a solution (and I'm normally good searching for solutions), but I seem to have an unique problem.
Let's assume that my current URL is http://www.something.com
I want to change all external links within webpages like the ones below...
1. <a href="http://other.something.com">other</a>
2. <a href="http://www.google.com">google</a>
... to this:
- <a href="http://www.something.com/redirect.htm?
http://other.something.com
">other</a> - <a href="http://ww开发者_JS百科w.something.com/redirect.htm?
http://www.google.com
">google</a>
I do NOT have PHP or ASP. Let's assume that my website is static HTML only. Is there a workable Apache URL rewrite solution?
Thank you
You can try mod_proxy_html. Quote from config guide:
Syntax: ProxyHTMLURLMap from-pattern to-pattern [flags] [cond]
This is the key directive for rewriting HTML links. When parsing a document, whenever a link target matches from-pattern, the matching portion will be rewritten to to-pattern.
mod_substitute might be an alternative.
- On the minus side, it is an unsophisticated regexp filter with all its drawbacks.
On the plus side, it is included in the default apache distribution and might be just enough to resolve your problem.
AddOutputFilterByType SUBSTITUTE text/html Substitute s|<a([^>]*)href="http(.?)://(.*)"([^>]*)>|<a $1 href="http://www.something.com?redirect=http$2://$3" $4>|i
Edit
If your site is indeed a set of static html pages, why not do an off-line transformation of them using a proper HTML DOM tool?
精彩评论