具有代理标志的 Apache 重写规则无法用于 mediawiki 服务
我有一个本地 apache httpd 托管一个 mediawiki 服务,该服务监听端口 3300。该服务可以通过
http://mylan:3300/wiki/
我配置互联网路由器以将端口转发条目添加到 mylan:3300 来访问我的 LAN。然后,我可以通过以下方式访问 wiki:
http://<dynamic domain>:3300/wiki/
接下来,我有一个在全球范围内提供服务的网站。 Web 服务器也是 apache httpd。我在 .htaccess 中添加了一条重写规则:
RewriteEngine On
RewriteRule ^/?wiki/?$ http://<dynamic domain>:3300/wiki/ [P]
我希望通过代理方法访问本地 LAN 上托管的 wiki,但使用全球互联网域名空间:
http://<internet domain>/wiki/
从互联网浏览器执行上述 URL 后,我可以看到 wiki 内容。但是,地址栏中显示的 URL 更改为
http://<dynamic domain>:3300/wiki/index.php/Main_Page
为了测试代理重写规则的工作,我尝试将重写规则更改为:
RewriteRule ^/?wiki/?$ http://www.google.com/search?q=test [P]
打开 URL:
http:///wiki/
引导我进入 google 搜索页面,但 URL 仍然存在如http:///wiki/。
任何想法为什么重写规则
RewriteRule ^/?wiki/?$ http://<dynamic domain>:3300/wiki/ [P]
使浏览器显示新的 URL 地址而不是互联网域名空间:
http://<internet domain>/wiki/
一个很好的例子是:
RewriteRule ^/?wiki/(.*)$ http://en.wikipedia.org/wiki/$1 [P]
如果我们访问该 url:
http://<domain>/wiki/Country
该 URL 将始终重写并显示为
http://en.wikipedia.org/wiki/Country
相反,我希望它显示
http://<domain>/wiki/Country
I have a local apache httpd hosting a mediawiki service that listen to port 3300. The service may access in my LAN via
http://mylan:3300/wiki/
I configure my internet router to add a port forwarding entry to the mylan:3300. I may then access to the wiki via something like:
http://<dynamic domain>:3300/wiki/
Next, I have a web site that serve globally. The web server is apache httpd too. I add a rewrite rule in .htaccess:
RewriteEngine On
RewriteRule ^/?wiki/?$ http://<dynamic domain>:3300/wiki/ [P]
I wish to access the wiki that host on my local LAN via the proxy method but using the global internet domain namespace:
http://<internet domain>/wiki/
After execute the above URL from internet browser, I can see the wiki contents. However, the URL shown in address bar change to
http://<dynamic domain>:3300/wiki/index.php/Main_Page
In order to test the proxy rewrite rule work, I try to change the rewrite rule to:
RewriteRule ^/?wiki/?$ http://www.google.com/search?q=test [P]
Open the URL:
http:///wiki/
lead me to google search page but the URL remain as http:///wiki/.
Any ideas why the rewrite rule
RewriteRule ^/?wiki/?$ http://<dynamic domain>:3300/wiki/ [P]
make the browser show the new URL address instead of internet domain name space:
http://<internet domain>/wiki/
A good example is:
RewriteRule ^/?wiki/(.*)$ http://en.wikipedia.org/wiki/$1 [P]
If we access the url:
http://<domain>/wiki/Country
The URL will always rewrite and shown as
http://en.wikipedia.org/wiki/Country
Instead, I expect it to show as
http://<domain>/wiki/Country
but the content is from http://en.wikipedia.org/wiki/Country
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能是包含完整链接的重定向。要重写它们,请添加以下内容:
我还注意到 Apache 在线文档中的 URL 重写指南- 内容处理部分中的高级主题,动态镜像子部分有以下示例:
Probably a redirect that includes the full link. To rewrite them add something like:
I also notice in the Apache online documentation for URL Rewriting Guide - Advanced topics in the section on Content Handling, sub section Dynamic Mirror has this example: