如何使用 Apache Rewrite 将用户重定向到完全限定的域名?
我对 apache mod_rewrite 模块真的很陌生。我的公司内网中有一个名为 http://abc
的页面。我希望用户每次在 URL 栏中输入 http://abc
时都会被重定向到 http://abc.somecompanyname.com
。有人可以提供示例或指出我正确的方向吗?
我认为这应该是一个很容易回答的问题。感谢大家的投入。
-标记
I'm really new to apache mod_rewrite module. I have a page called http://abc
in my company intranet. I want users to be redirected to http://abc.somecompanyname.com
whenever they type http://abc
to the URL bar. Could someone please provide and example or point me in the right direction.
I figure this should be quite an easy question to answer. Thanks everyone for you inputs.
-Mark
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
引自 Apache 2.4 文档:
这确实需要另一个虚拟主机,但并不缺少这些。该解决方案对我来说非常有效 - 我喜欢如何将“不需要的”主机的重定向和规范主机的配置分开。
Quote from Apache 2.4 documentation:
This does require another virtual host, but there's no shortage of those. The solution works very well for me - and I like how redirection of 'unwanted' hosts and configuration of the canonical host are separated.
您可以使用像这样简单的 VirtualHost 定义来完成此任务,在处理 abc 请求的服务器上:
You could accomplish that with a VirtualHost definition as simple as this, on the server handling requests for abc:
我发现 Apache2 URL 重写指南 中的建议效果更好。
我最终得到:
Apache2 示例中未包含“RewriteEngine on”行。也许它通常是默认打开的,但就我而言,我需要添加它。
I found the advise in the Apache2 URL Rewriting Guide worked better.
I ended up with:
The "RewriteEngine on" line wasn't included in the Apache2 example. Maybe it's usually on by default but in my case I needed to add it.