.htaccess 域名未知时重定向
我有一个网站,我不确定它上线后的域名最终会是什么,但当我正在处理它时,我通过本地服务器访问它。站点上的目录之一需要重定向。为了节省网站上线时的时间(也只是为了了解如何实现),我尝试编写一个 .htaccess 语句,无论域名是什么,该语句都会重定向目录。目前,我通过以下方式访问该网站:
http://phuk9220/
我想要此目录:
/audio/help-and-faqs/
重定向到:
/audio/help-and-faqs/welcome/
现在,我可以轻松地执行此操作:
RedirectMatch 301 ^/audio/help-and-faqs/$ http://phuk9220/audio/help-and-faqs/welcome/
但是,这意味着将 http://phuk9220/ 更改为它将要的任何域最终开启。无论如何,是否可以根据域的实际位置动态更改域?
提前致谢,如果您有任何疑问,请询问。
亚历克斯
I have a site that I am not sure what the domain name will eventually be when it's live, but as I am working on it I access it through a local server. One of the directories on the site needs to be redirected. To save time when the site goes live (and also just to learn how) I am trying to write a .htaccess statement that will redirect the directory regardless of what the domain name is. Currently I access the site through:
http://phuk9220/
I want this directory:
/audio/help-and-faqs/
to redirect to:
/audio/help-and-faqs/welcome/
Now, I can easily do this with:
RedirectMatch 301 ^/audio/help-and-faqs/$ http://phuk9220/audio/help-and-faqs/welcome/
However, it means changing the http://phuk9220/ to whatever domain will it will eventually be on. Is there anyway of changing the domain dynamically depending on where it actually is ?
Thanks in advance and if you have any questions, please ask.
Alex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需完全省略域名即可在请求的同一域上进行重定向。
Simply omitting the domain name entirely should do the redirect on the same domain that was requested.