apache - Laravel 路由不起作用,Apache 配置仅允许 public/index.php/route

标签 apache .htaccess laravel

示例:

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。

最佳答案

造成此行为的两个最常见原因是:

  1. mod_rewrite 未启用

    sudo a2enmod rewrite && sudo service apache2 restart

  2. AllowOverride设置为None,设置为All,假设Apache2.4

    sudo nano /etc/apache2/apache2.conf

搜索<Directory /var/www/>并更改AllowOverride NoneAllowOverride All ,然后保存文件并重新启动apache

关于apache - Laravel 路由不起作用,Apache 配置仅允许 public/index.php/route,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24784606/

相关文章:

regex - htaccess 目标特定文件

php - 获取完整干净的 URL

php - Htaccess 重写目录到文件

laravel - 更改 Blade 模板中的日期格式

php - 在 Laravel 中使用 JSON 列

php - Paypal php Rest API,重定向时出现 "Got Http response code 404"错误

php - 覆盖每个虚拟主机的 php_value

ruby-on-rails - 用 yum 安装的 mod_passenger.so 在哪里?

apache - CodeIgniter htaccess 子文件夹问题

apache - 我应该在 htaccess 中重写的 url 上放置重定向吗?