-此问题不会发生在已部署的 Heroku 应用程序上,而只会发生在本地域上。 -index.php和.htaccess存储在(root)/public
我的问题是,XAMPP 似乎无法读取 .htaccess,当我尝试访问 domain.local 时,它不会重定向到 index.php,并且完全公开了应用程序的文件夹和文件。
当我尝试访问域 arcadia-2025-lastrun.local 时,我找到了应用程序中存在的文件夹列表和所有文件,而不是重定向到 index.php。我想强调的是,index.php 和 .htaccess 位于 (root)/public/
我事先做了本地域名,VirtualHost如下:
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\ARCADIA-2025-LASTRUN"
ServerName ARCADIA-2025-LASTRUN.local
</VirtualHost>
我将其作为 .htaccess — 部署到 Heroku 时不会出现任何问题:
RewriteEngine On
#accept loading of actual files and directories
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#send everything else to the index page
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
问题解决了。
XAMPP 不会像 Heroku 那样自动查找 /public。
在 httpd-vhosts.conf 中添加 /public 文件夹
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\ARCADIA-2025-LASTRUN/public"
ServerName ARCADIA-2025-LASTRUN.local
<Directory "C:/xampp/htdocs/ARCADIA-2025-LASTRUN/public">
Options -Indexes
AllowOverride All
Require all granted
</Directory>
</VirtualHost>