根目录内的文件无法访问 mod_rewrite PHP
文件结构看起来像这样
- root
- root/x
- root/x/y.php
- root/index.php
.htaccess 代码
RewriteRule (.*) /x/$1 [L]
htaccess 文件的作用是从 url 中删除文件夹名称 (x),以便访问 y.php = http://localhost/y.php 而不是 http://localhost/x/y.php 。这可行,但我现在的问题是index.php 显示如下内容:
Index of /x
Parent Directory
y.php
我无法访问index.php。我相信 x 成为根文件夹。 感谢您的帮助!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您不应该允许在公共服务器上像这样显示索引...在您的本地主机上可能没问题,但是您仍然可以通过添加以下内容在 .htaccess 中禁用它:
要解决您的问题,您可能应该添加在重写规则之前满足以下条件,以便该规则不会应用于磁盘上实际存在的任何文件或目录:
这不会解决您遇到的问题,因为 .htaccess 正在重定向到不存在的 / x/index.php文件...这就是为什么它显示 /x 目录的索引列表
First, you shouldn't allow index displays like this on a public server ... on your localhost it may be okay, but still, you can disable it in your .htaccess by adding this:
To address your question, you should probably add the following conditions before your rewrite rule so that the rule won't apply to any files or directories that actually exist on disk:
This won't fix the issue you have because the .htaccess is redirecting to a non-existant /x/index.php file ... this is why it's showing the index listing for the /x directory