.htaccess - 使用 Rewrite Proxy 指令“屏蔽”外部 URL 链接

标签 .htaccess url-rewriting isapi

我有一个简单的重写规则,它使用 Helicon Isapi_Rewrite 3 RewriteProxy 指令写入外部域。

示例:RewriteProxy 博客 http://blog.com

但是,外部站点上的链接并没有像我预期的那样被代理屏蔽。他们仍然指向http://blog.com/link1而不是http://mysite/blog/link1 .

有人能给我指出解决这个问题的正确方向吗?

谢谢

最佳答案

Helicon Tech 论坛上的讨论解决了同样的问题。 http://www.helicontech.com/forum/8460-rewrite_proxy_to_2d_machine.html

第一个示例提供了 ISAPI Rewrite 2 的代码,但该线程在页面下方包含了 ISAPI Rewrite 3 语法。以下是针对您的示例的版本 3 代码的改编。

RewriteEngine on
RewriteBase /
RewriteRule ^blog$ http://mysite/blog/ [NC,R=301]
RewriteProxy ^/blog(/.*)?$ http\://blog.com$1 [NC,U]

(这未经测试,因为我正在运行 ISAPI Rewrite 2。)请注意,在尝试反向代理我的“主”域下的另一个站点时,我遇到了一些障碍。您可能也会发现这些问题。

1) 非相对链接

除非应用程序从头开始编码以假设反向代理,否则我发现它可能会崩溃。使用所有相关链接的简单 HTML 页面(例如)就可以了。但是,通过包含此代码的反向代理提供 HTML 将映射到 http://mysite/page_from_the_root.html 。 ISAPI Rewrite 不知道拦截该请求,但如果用户的浏览器点击http://mysite/blog/page_from_the_root.html,它会代理内容。

2) Cookie

Blog.com 可能会从 blog.com 域写入 cookie。通过 MySite 域提供的页面可能无法访问这些 cookie,具体取决于用户的浏览器设置。

3) JavaScript 和 AJAX

4) SSL 证书

关于.htaccess - 使用 Rewrite Proxy 指令“屏蔽”外部 URL 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/759645/

相关文章:

apache - 如何使用 htaccess 从 url 中删除查询字符串

.htaccess - 我的 htaccess 规则不适用于实时服务器上的项目(htaccess 在文件夹内)

asp.net - 带有波形符 (~) 的 IIS URL 重写问题

.htaccess RewriteRule 重写我的 css、js 和图像文件

iis-7 - ISAPI 扩展在 IIS7 上给出 404

c++ - ISAPI 扩展 : What is the difference between TerminateExtension and the extensions destructor?

linux - 如何使用 URL 重写在我的站点中反射(reflect)另一个站点?

php - 使用 mod_rewrite 的 .htaccess 新手问题

php - htaccess 重写子域,没有文件名映射和扩展名

linux - 某些 Htaccess 命令阻止了我的 linux cron 作业