Apache mod_rewrite - 从子域重写到主域
我想将网址 abc.xyz.com/123 重定向到 xyz.com。因此,将访问的文件将是xyz.com 的index.php。该index.php应该可以使用abc和123(因此123将是$_SERVER['PHP_SELF'],并且abc将来自$_SERVER['HTTP_HOST'])以启用适当的处理。
abc.xyz.com 已经转到 xyz.com(尽管由我的服务提供商配置),并且可以从 $_SERVER['HTTP_HOST'] 中提取 abc。但是,abc.xyz.com/123 似乎正在 xyz.com 的根目录中查找名为 123 的文件夹,并且在找不到任何文件夹时显示 404 错误。
有人可以给我要放入 .htaccess 中的行,以使 abc.xyz.com/123 能够调用 xyz.com 的 index.php (通过 $_SERVER['PHP_SELF'] 可以使用 123 吗?我不能似乎可以正常工作了,
非常感谢您的宝贵时间!
I want to redirect a url abc.xyz.com/123 to xyz.com. So the file that will be accessed will be index.php of xyz.com. That index.php should have available to it both abc and 123 (so 123 will be $_SERVER['PHP_SELF'], and abc will come out of $_SERVER['HTTP_HOST']) to enable appropriate processing.
abc.xyz.com already goes to xyz.com (though configuration by my service provider), and abc can be extracted out of $_SERVER['HTTP_HOST']. However, abc.xyz.com/123 seems to be looking for a folder called 123 in the root directory of xyz.com, and is showing up a 404 error when it cannot find any.
Can someone kindly give me the line(s) to be put in .htaccess to enable abc.xyz.com/123 to call index.php of xyz.com (with 123 being available though $_SERVER['PHP_SELF']? I cannot seem to get it to work.
Thank you very much for your time!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许是这样的:
所以,基本上,如果 HTTP 主机包含 .xyz.com(前面的点的存在确保它只发生在子域),那么所有内容都会发送到 index.php,并附加域后面的内容如 $_GET['param']。
Perhaps something like:
So, basically, if the HTTP host contains .xyz.com, (the presence of the dot at the front makes sure it only happens for subdomains) then everything is sent to index.php with whatever is after the domain attached as $_GET['param'].
谢谢卡扎尔的建议。我在上面找到了子域子目录重定向问题的解决方案,如下:
Thanks, Kazar, for the suggestion. I found the solution for my subdomain subdirectory redirection problem above, here it is: