如何使用Apache mod_rewrite或RewriteCond重写外部链接(重定向到退出页面)? [英] 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.
假设我的当前 URL是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>
...对此:
- < a href =" http://www.something.com/redirect.htm?
http://other.something.com
"> other</a> - < a href =" http://www.something.com/redirect.htm?
http://www.google.com
"> google</a>
- <a href="http://www.something.com/redirect.htm?
http://other.something.com
">other</a> - <a href="http://www.something.com/redirect.htm?
http://www.google.com
">google</a>
我没有PHP或ASP.假设我的网站仅是静态HTML.有可行的Apache URL重写解决方案吗?
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?
谢谢
推荐答案
mod_substitute 可能是替代方法.
- 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
修改
如果您的网站确实是一组静态html页面,为什么不使用适当的HTML对其进行离线转换 DOM 工具?
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?
这篇关于如何使用Apache mod_rewrite或RewriteCond重写外部链接(重定向到退出页面)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!