要解决Apache只允许index.php在根目录运行的问题,可以在Apache的配置文件中添加以下代码:
Options -Indexes
RewriteEngine On
RewriteRule ^$ /index.php [L]
请将/path/to/root/directory
替换为你的根目录路径。
这段代码的作用是禁用目录列表功能,并使用Rewrite规则将根目录请求重定向到index.php文件。
重新启动Apache服务器后,它将只允许index.php在根目录运行。如果用户尝试访问根目录中的其他文件,将会被重定向到index.php。
这样做可以增强网站的安全性,并确保只有index.php能在根目录中运行。