听起来您的 URL 重写不起作用。如果在/api 之前的 URL 中添加index.php 是否有效?
例如,yourdomain.com/api 将变为 yourdomain.com/index.php/api,如果第二个 URL 有效,则重写无效。
如果您的重写不起作用,但您的public 目录中有.htaccess 文件,那么您可能需要在您的Apache 配置中允许覆盖。这是 Ubuntu 上 Lumen 的示例虚拟主机配置。
我已经标记了您需要更改的行。将第一个和第三个更改为指向您网站目录中的public 目录。然后将第二行更改为您在网站上使用的域名。
<VirtualHost *:80>
DocumentRoot "/var/www/lumen/public" # Change this line
ServerName yourdomain.com # Change this line
<Directory "/var/www/lumen/public"> # Change this line
AllowOverride All # This line enables .htaccess files
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
您需要重新启动 Apache 才能使这些设置生效。
更好的方法
启用.htaccess 文件应该可以工作,但使用.htaccess 会降低您的网站速度。最好的解决办法是将.htaccess文件的内容放到你的虚拟主机中,然后禁用.htaccess文件。
示例虚拟主机配置如下所示:
<VirtualHost *:80>
DocumentRoot "/var/www/lumen/public" # Change this line
ServerName yourdomain.com # Change this line
<Directory "/var/www/lumen/public"> # Change this line
# Ignore the .htaccess file in this directory
AllowOverride None
# Make pretty URLs
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
</VirtualHost>
再一次,您需要重新启动 Apache 才能使这些设置生效。