如何使用Apache mod_rewrite或RewriteCond重写外部链接(重定向到退出页面)? [英] How to rewrite external links (redirect to an Exit Page) with Apache mod_rewrite or RewriteCond?

查看:90
本文介绍了如何使用Apache mod_rewrite或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>

...对此:

  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>
  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>

我没有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 可能是替代方法.

  • 在不利的一面,它是一个简单的正则表达式过滤器,带有所有 缺点.
  • 从正面来看,它包含在默认的Apache发行版中,可能足以解决您的问题.

  • 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆