Laravel Routes 不工作,Apache 配置只允许 public/index.php/route [英] Laravel Routes not working, Apache configuration only allows for public/index.php/route

查看:26
本文介绍了Laravel Routes 不工作,Apache 配置只允许 public/index.php/route的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例:

Route::get('/get', function() {
    return 'get';
});

要查看上面的路线,我必须导航到 public/index.php/get.

To view the route above, I must navigate to public/index.php/get.

我已经查看了很多 SO 帖子,并在谷歌上尝试了不同的东西,但没有任何区别(是的,我每次都重新启动 apache).

I've viewed quite a few SO posts and googled around trying different things and it hasn't made a difference (yes I restart apache every time).

这是我在公共目录中的 .htaccess:

Here is my .htaccess in the public directory:

<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.

What could be causing this still? I'm running Ubuntu.

推荐答案

您是否在 apache 上安装并启用了 mod_rewrite?尝试删除 if 行 ( 和 ) 并查看在您尝试加载网站时是否会引发错误.如果是,请运行 sudo a2enmod rewrite 并重新启动 apache.

Do you have mod_rewrite installed and enabled on apache? Try to remove the if lines ( and ) and see if it throws an error when you try to load the website. If it does, run sudo a2enmod rewrite and restart apache.

这是我在 public/目录中的 .htaccess:

This is the .htaccess I have on my public/ directory:

<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>

这篇关于Laravel Routes 不工作,Apache 配置只允许 public/index.php/route的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆