htaccess 递归是如何工作的?
我在托管环境中工作,主 webroot 位于 ~/www
中。我在 ~/www/__subdomains
中托管了多个子域。在主 webroot 中,我有一个 .htaccess 文件,它进行了一些小的重写。在我的两个子域中,我有类似的 .htaccess
文件,并且这些子域响应正确。
在另外 2 个新创建的子域中,我有 .htaccess
文件,这些文件为空,保存了 AddHandler
指令。我发现根 .htaccess
文件的存在/内容会影响这两个子域。他们抛出 500 错误。一旦我重命名该子域,损坏的子域就可以工作。
当然,这会破坏其他站点,因此我不能将其移走,但这违反了我对 .htaccess 递归工作原理的理解。我认为只要子目录中有 .htaccess
文件,祖先目录中的文件就永远不会被执行。
显然,我的想法是错误的,所以我希望有人可以教育我并帮助我解决这个问题。
谢谢。
I'm working in a hosted situation where I have a primary webroot located in ~/www
. I have several subdomains hosted in ~/www/__subdomains
. In the primary webroot, I have a .htaccess
file that does a bit of minor rewriting. In two of my subdomains, I have similar .htaccess
files and these subdomains respond properly.
In 2 other, newly created subdomains, I have .htaccess
files that are empty save for an AddHandler
directive. What I'm finding is that the root .htaccess
file's existence/content affects these 2 subdomains. They throw a 500 error. As soon as I rename that one, the broken subdomains work.
This, of course, breaks the other sites so I can't just move this off, but it violates my understanding of how .htaccess
recursion works. I thought that as long as there was a .htaccess
file in a subdirectory, those in ancestor directories would never get executed.
Clearly, I'm wrong about that so I'm hoping someone can educate me and help me get this fixed.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
.htaccess
文件从当前目录向上应用,在主配置处停止。当前目录的.htaccess
文件中的任何规则和指令将取代进一步评估.htaccess
时找到的任何其他规则。然而,正如您所发现的,问题在于未明确覆盖的规则是从其他文件应用的。您可以参考 Apache .htaccess 教程以获得进一步的解释,特别是如何应用指令部分。
希望有帮助。
.htaccess
files are applied from the current directory up, stopping at the main configuration. Any rules and directives that are in the current directory's.htaccess
file, supersede any other rules found while evaluating.htaccess
further up.However, the problem, as you've found, is that rules that aren't explicitly overridden, are applied from the other files. You can reference the Apache .htaccess Tutorial for further explanation, specifically, the How directives are applied section.
Hope that helps.