示例:
Route::get('/get', function() {
return 'get';
});
要查看上面的路线,我必须导航到 public/index.php/get。
我看过很多 SO 帖子,并在 google 上搜索尝试不同的东西,但并没有产生什么影响(是的,我每次都重新启动 apache)。
这是我在公共(public)目录中的 .htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
</IfModule>
# For all files not found in the file system, reroute the request to the
# "index.php" front controller, keeping the query string intact
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
什么可能导致这个问题?我正在运行 Ubuntu。
最佳答案
造成此行为的两个最常见原因是:
mod_rewrite 未启用
sudo a2enmod rewrite && sudo service apache2 restart
AllowOverride
设置为None,设置为All,假设Apache2.4sudo nano /etc/apache2/apache2.conf
搜索<Directory /var/www/>
并更改AllowOverride None
至AllowOverride All
,然后保存文件并重新启动apache
关于apache - Laravel 路由不起作用,Apache 配置仅允许 public/index.php/route,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24784606/