【问题标题】:Laravel route not found with https使用 https 找不到 Laravel 路由
【发布时间】:2016-08-14 02:17:20
【问题描述】:

我在 routes.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>

请指导我。

谢谢。

【问题讨论】:

标签: php http https laravel-5.2


【解决方案1】:
  • 更新.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>

【讨论】:

  • “不适合我”会更合适,@RaeIan。 Laravel 5.8 (laravel.com/docs/5.8/releases) 中没有任何改变会使这个修复过时。 APP_URL 仍然存在,其余的是 Apache 配置,与 Laravel 版本无关。你只是有一个不同的问题。
  • 它按预期工作,非常感谢你的伙伴!
【解决方案2】:

我面临同样的问题,我通过简单地修改了我的 .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>

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

【讨论】:

  • 请查看我的 .htaccess 是否需要更改?因为我粘贴了你的 .htaccess 并且它给出了内部服务器错误。
  • 用你的项目路径替换
  • 只需在您的 .htaccess 文件中添加这一行 'RewriteBase '
  • 我按照您的建议做了,但它为所有路由提供了内部服务器错误。 .但主页加载正常
【解决方案3】:

如果有人在 Laravel 中遇到无限循环问题,有一个解决方案:

RewriteEngine On

# If we receive a forwarded http request from a proxy...
RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]

# ...or just a plain old http request directly from the client
RewriteCond %{HTTP:X-Forwarded-Proto} =""
RewriteCond %{HTTPS} !=on

# Redirect to https version
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

【讨论】:

    猜你喜欢
    • 2018-02-22
    • 2016-11-15
    • 1970-01-01
    • 2020-03-26
    • 2017-05-25
    • 2014-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多