【发布时间】:2021-10-13 00:32:48
【问题描述】:
上下文
我正在尝试更改我的 XAMPP Apache 设置的根目录。目前,根目录为/htdocs。我的项目文件夹名为“Real Website”,所以我希望根目录为/htdocs/Real Website,这样我就可以像在实时网站上一样使用根目录引用文件(我必须将“Real Website”添加到根引用[/Real Website/] 在引用本地主机上的特定文件之前,而不是像我在实时服务器上那样使用“/”)。
为此,我进入了 httpd.conf 文件 (XAMPP/xamppfiles/etc/httpd.conf)。我从
编辑了以下几行DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
<Directory "/Applications/XAMPP/xamppfiles/htdocs">
到
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/Real Website"
<Directory "/Applications/XAMPP/xamppfiles/htdocs/Real Website">
我还编辑了第一个目录标签,如下所示:
<Directory />
AllowOverride all
Require all granted
</Directory>
在进行这些更改后进入“真实网站”文件夹中的文件后,我在 JavaScript 中添加了 window.location.href = "/" 行,以查看它是否会显示“真实网站”文件夹。我收到了这个错误:
Access forbidden!
You don't have permission to access the requested directory. There is either no index document or the directory is read-protected.
If you think this is a server error, please contact the webmaster.
Error 403
localhost
Apache/2.4.46 (Unix) OpenSSL/1.1.1h PHP/7.4.12 mod_perl/2.0.11 Perl/v5.32.0
URL 也只显示“localhost”。
检查错误日志后,我得到了更多信息:
[Mon Aug 09 00:21:55.011957 2021] [authz_core:error] [pid 78225] [client ::1:56063] AH01630: client denied by server configuration: /Applications/XAMPP/xamppfiles/htdocs/, referer: https://localhost/Real%20Website/index.php
问题
知道为什么我会收到“禁止访问!”更改根目录后报错?
我尝试过的事情
我将“Require all denied”这行改成“Require all grant”,如下图,没有用(可能这些行没有影响)。
<Directory "/Applications/XAMPP/xamppfiles/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
另外,这是文件夹目录的配置:
<Directory "/Applications/XAMPP/xamppfiles/htdocs/Real Website">
Options Indexes FollowSymLinks ExecCGI Includes
AllowOverride All
Require all granted
</Directory>
我还尝试将“Real Website”文件夹的文件权限更改为 777,但也没有用。
这可能与两个单词的文件夹名称有关吗? “真实”和“网站”之间的空间是否会成为问题?我在尝试向 .htaccess 添加内容时遇到了问题,所以我想知道这是否也是这里的问题。
如果有任何问题,请告诉我。
【问题讨论】: