I'm setting up my laravel application and every time I run php artisan serve, it starts a laravel development serve at localhost:8000. Bu when i open the locahost link on the browser, it forces the http to https and logs invalid request (unsupported SSl request). What do you advise me to do to resolve this?

我已经试着将HTTPS mod rewrite规则强制设置为http://上的.htaccess文件,它仍然存在.

This is the command line

C:\Users\topaz\cashurban>php artisan serve
Laravel development server started: <http://127.0.0.1:8000>
[Thu Aug 22 23:06:07 2019] 127.0.0.1:60410 Invalid request (Unsupported SSL request)
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60418 Invalid request (Unsupported SSL request)
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60419 Invalid request (Unsupported SSL request)
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60420 Invalid request (Unsupported SSL request)
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60421 Invalid request (Unsupported SSL request)
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60423 Invalid request (Unsupported SSL request)
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60409 [200]: /assets/img/slider-1.jpg
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60425 Invalid request (Unsupported SSL request)
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60426 Invalid request (Unsupported SSL request)
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60427 Invalid request (Unsupported SSL request)
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60411 [200]: /assets/img/slider-2.jpg
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60435 Invalid request (Unsupported SSL request)
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60437 [200]: /assets/img/slider-3.jpg
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60439 [200]: /assets/img/icon-1-1.png
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60438 [200]: /assets/img/images/index-Recovereddashboard_03.png
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60440 [200]: /assets/img/icon-2-1.png
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60442 [200]: /assets/img/icon-3-1.png
[Thu Aug 22 23:06:08 2019] 127.0.0.1:60447 Invalid request (Unsupported SSL request)
[Thu Aug 22 23:06:09 2019] 127.0.0.1:60448 [200]: /assets/img/tor1.png
[Thu Aug 22 23:06:09 2019] 127.0.0.1:60450 [200]: /assets/img/tor2.png
[Thu Aug 22 23:06:09 2019] 127.0.0.1:60452 [200]: /assets/img/tor3.png
[Thu Aug 22 23:06:09 2019] 127.0.0.1:60455 [200]: /assets/img/images/visa.png
[Thu Aug 22 23:06:09 2019] 127.0.0.1:60453 [200]: /assets/img/images/remita.png
[Thu Aug 22 23:06:09 2019] 127.0.0.1:60454 [200]: /assets/img/images/master-card.png
[Thu Aug 22 23:06:09 2019] 127.0.0.1:60460 [200]: /assets/img/images/verve.png
[Thu Aug 22 23:06:09 2019] 127.0.0.1:60461 [200]: /assets/img/images/indexpartners_11.png
[Thu Aug 22 23:06:09 2019] 127.0.0.1:60462 [200]: /assets/img/images/bank-branches.png
[Thu Aug 22 23:06:09 2019] 127.0.0.1:60463 [200]: /assets/img/images/indexpower_03.png
[Thu Aug 22 23:06:09 2019] 127.0.0.1:60464 [200]: /assets/img/images/paystack.png
[Thu Aug 22 23:06:09 2019] 127.0.0.1:60465 [200]: /assets/img/images/chams.png
[Thu Aug 22 23:06:10 2019] 127.0.0.1:60468 Invalid request (Unsupported SSL request)
[Thu Aug 22 23:06:10 2019] 127.0.0.1:60469 Invalid request (Unsupported SSL request)

this is the .htaccess file

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

    RewriteEngine On

    #Force Https

    #RewriteCond %{HTTPS} !=on
    #RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d

    #Api Redirect
    RewriteCond %{REQUEST_URI} (.+)/$
    #RewriteRule ^/api$ api.%{REQUEST_URI} [L,R=301]


    RewriteCond %{REQUEST_URI} (.+)/$
    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}]

    #GZip Compression
    <ifModule mod_gzip.c>
      #mod_gzip_on Yes
      #mod_gzip_dechunk Yes
      #mod_gzip_item_include file .(html?|txt|css|js|php|xml|json|pl)$
      #mod_gzip_item_include handler ^cgi-script$
      #mod_gzip_item_include mime ^text/.*
      #mod_gzip_item_include mime ^application/x-javascript.*
      #mod_gzip_item_exclude mime ^image/.*
      #mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
    </ifModule>

    #php_value auto_prepend_file /home/example_project/public_html/error_handler_slack.php
    php_value auto_prepend_file error_handler_slack.php
</IfModule>

我希望它在http://localhost而不是https://localhost上运行,因为它目前正在重定向

推荐答案

我后来解决了这个问题,以防将来有人遇到类似的问题,我发现AppServiceProvider类有一个register方法,其中注册了一个安全拦截中间件,以强制每个http请求发送到https.因此,我所做的是编写一个if-Else逻辑,以便仅在生产环境中允许这样做,因为我的本地主机没有SSL证书.

in app/providers/AppServiceProvider.php

look for the register() method, the implement the logic by checking tha app is local or not. The isLocal() function checks your .env file for APP_ENV variable and returns true if is local, so you reconfirm again that that is set to local and be sure to clear any previous configuration cache.

//check that app is local
if ($this->app->isLocal()) {
//if local register your services you require for development
    $this->app->register('Barryvdh\Debugbar\ServiceProvider');
} else {
//else register your services you require for production
    $this->app['request']->server->set('HTTPS', true);
}

Laravel相关问答推荐

我是否需要/是否可以从控制器运行LARLAVEL备份?

在Vite list 中找不到文件:Resources/scss/hrms.scss.如何使用LARAVEL VITE解决这个问题?

Laravel复选框值更新

在 Laravel 中排序的集合在 Vue 中突然不再排序

Laravel REST API:如何将数据库列名与参数的另一个名称映射?

Laravel AppServiceProvider 中的代码在通过 DeployHQ 部署时停止 Composer 和构建

我的共享主机上的每个帖子请求都出现 503 服务不可用

如何使用动态翻译键翻译 Laravel硬编码字符串(还有 1 个错误)..(验证异常类)

从主类别模型 laravel 中获取子类别翻译

在 Laravel 中清除 Routes&config:cache 后未定义的常量

不能在 laravel 中使用控制器名称,必须使用命名空间

链接到容器时如何使用主机网络?

Laravel 合集日期比较

如何使用 laravel eloquent 获得select count(*) group by

从 sqlite DB 登录 Laravel,得到PDOException 找不到驱动程序

将 hasOne 模型附加到另一个 Laravel/Eloquent 模型而不指定 id

Http请求多浏览器的烦恼

日期时间格式无效:1366 字符串值不正确

如何使 Laravel (Blade) 文本字段只读

带有 Xdebug 的 Laravel 5 总是抛出The payload is invalid..