使用 https 找不到 Laravel 路由


Laravel route not found with https

我在路由中定义了一个简单的路由.php在任何路由之上:

Route::get('/test', function () {
echo 'hello';
});

当通过http访问时,它正在工作,但它提供:

The requested URL /test was not found on this server.

当我尝试通过https访问时。

我在互联网上搜索了很多,但找不到任何解决方案。

我的主页同时加载了 http 和 https,但其他路由不起作用。我需要一些额外的配置吗?

编辑:

.htaccess:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]
    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

</IfModule>

请指导我。

谢谢。

  • 更新.env文件中的APP_URL,使其以https://开头而不是http://

    APP_URL=https://yourserver.com

  • 将此添加到您的SSL Apache配置中(在Ubuntu上:default-ssl.conf):

<Directory /var/www/public/>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  allow from all
</Directory>

我面临着同样的问题,我通过简单地修改我的 .htaccess 文件解决了它。通常,这是我们重写模块的问题。试试这个希望它对你有用。

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

还要确保本地服务器和生产服务器上的文件夹结构匹配。