0

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:

  1. <a href="http://www.something.com/redirect.htm?http://other.something.com">other</a>
  2. <a href="http://www.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

slashline
  • 169
  • 1
  • 3
  • 9
  • 2
    Apache does not alter page content, `mod_rewrite` is for incoming URLs only. – Orbling May 03 '11 at 17:00
  • Have you considered JavaScript? – clmarquart May 03 '11 at 17:04
  • @clmarquart: That would still require alteration to the page content. If he can do that, he could probably rewrite all the URLs by hand. Though of course if there are many, it would be preferable with code. – Orbling May 03 '11 at 17:06
  • I can't rewrite all URLs by hand because it's a massive website (over 1,000 pages) and people contribute to it using Macromedia Contribute. That means they can't easily code in external URLs by hand. I know, a CMS is better, but we're still limited to static HTML. I'll try some of the answers on this page and then vote. – slashline May 24 '11 at 21:32

2 Answers2

1

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.

Timofey Stolbov
  • 4,501
  • 3
  • 40
  • 45
1

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?

Community
  • 1
  • 1
Anders Lindahl
  • 41,582
  • 9
  • 89
  • 93