重写已经重定向的 URL?
我正在运行具有动态 IP 地址的 Apache2 Web 服务器。我购买了 exampledomain.net,并且使用 no- ip.com 的域名更新服务可将所有访问者重定向到我当前的 IP 地址(尾注 #1)。例如,有人访问 exampledomain.net,他们会被重定向到 73.181.57.34。它就像一个魅力。然而,它并不是那么用户友好。我可以重写重定向的 IP 地址 URL 吗?
我在根文件夹的 .htaccess 中尝试了这些重写规则...
RewriteEngine On
RewriteCond %{HTTP_HOST} ^73\.181\.57\.34:88
RewriteRule ^(.*)$ http://www.exampledomain.net/$1 [L,NC]
# I simplified the RewriteCond. I would use regex in a real situation.
当然,这会创建一个无限循环。用户访问www.exampledomain.net。它们被 no-ip 重定向到 73.181.57.34:88。 Apache 将它们重定向到 www.exampledomain.net,后者将它们重定向回 73.181.57.34:88...等等。
在重写方面我是个菜鸟,但是有没有办法在不重定向的情况下重写 URL?
我也尝试了这些重写规则(黑暗中的一枪)......
RewriteEngine On
RewriteCond %{HTTP_HOST} ^73\.181\.57\.34:88
RewriteRule ^(.*)$ my.exampledomain.net/$1 [L,NC]
# I'd read that Apache replied with a redirect header when you include http
当然,这不起作用,因为 my.exampledomain.net 并不真正存在。
谢谢!
(1) No-IP 的工作原理是这样的:您在服务器上下载并安装他们的动态更新客户端。每隔几分钟,它就会轮询您的服务器以获取其当前的外部 IP 地址。如果更改,它会更新 no-ip 记录中服务器的 IP 地址。
I'm running an Apache2 web server with a dynamic IP address. I bought exampledomain.net, and I use no-ip.com's domain-update service to redirect any visitors to my current ip address (endnote #1). For example, someone visits exampledomain.net and they get redirected to 73.181.57.34. It works like a charm. However, it isn't all that user-friendly. Can I rewrite the redirected, ip-address URL?
I tried these rewrite rules in the root folder's .htaccess...
RewriteEngine On
RewriteCond %{HTTP_HOST} ^73\.181\.57\.34:88
RewriteRule ^(.*)$ http://www.exampledomain.net/$1 [L,NC]
# I simplified the RewriteCond. I would use regex in a real situation.
Of course, this creates an infinite loop. The user visits www.exampledomain.net. They're redirected to 73.181.57.34:88 by no-ip. Apache redirects them to www.exampledomain.net which redirects them back to 73.181.57.34:88... so on and so forth.
I'm a noob when it comes to rewriting, but is there a way to rewrite a URL without redirecting?
I tried these rewrite rules too (a shot in the dark)...
RewriteEngine On
RewriteCond %{HTTP_HOST} ^73\.181\.57\.34:88
RewriteRule ^(.*)$ my.exampledomain.net/$1 [L,NC]
# I'd read that Apache replied with a redirect header when you include http
Of course, this doesn't work because my.exampledomain.net doesn't really exist.
Thanks!
(1) No-IP works like this: You download and install their dynamic update client on your server. Every couple of minutes it polls your server for its current external ip address. If it's changed, it updates your server's ip address in no-ip's records.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不可以。例如,我无法向您显示我的网站,并且 http://yourbank.example.com地址不好。
No. For example I can't show you my website and have http://yourbank.example.com in the address bad.