【问题标题】:Getting Error 'The GET method is not supported for this route. Supported methods: HEAD'出现错误'此路由不支持 GET 方法。支持的方法:HEAD'
【发布时间】:2021-03-12 03:24:09
【问题描述】:

Error Image here

登录路径

Route::get('/', [HomeController::class, 'index'])
    ->name('index')
    ->breadcrumbs(function (Trail $trail) {
        $trail->push(__('Home'), route('frontend.index'));
    });

身份验证路由

Route::get('login', [LoginController::class, 'showLoginForm'])->name('login');
Route::post('login', [LoginController::class, 'login']);

问题:

我的项目在本地运行时运行良好,但当我将其上传到服务器时,它显示方法不允许异常。我不知道为什么。 当我以前运行像 www.domain.com/billingsystem/ 这样的 URL 时,会出现上述错误,但是当我像 www.domain.com/billingsystem/index.phpwww.domain.com/billingsystem/public 这样运行 URL 时在服务器上运行良好。 我实际上没有找到解决这个问题的任何人请帮我解决这个问题。

感谢和问候。

【问题讨论】:

    标签: php laravel routes laravel-7 boilerplate


    【解决方案1】:

    这与您的网络服务器配置有关。 Laravel 使用 index.php 文件作为其所有请求的入口点。所以你必须告诉你所有的子路由都通过这个文件。配置取决于您使用的 Web 服务器。我将向您展示如何使用 nginxapache2 修复它。

    nginx

    打开配置文件(通常位于/etc/nginx/sites-avialable/default)并在location 部分下,编辑该行:

    try_files $uri $uri/ =404;
    

    try_files $uri $uri/ $uri/index.php =404;
    

    保存文件并使用sudo service nginx restart重新启动nginx

    apache2

    对于apache2,您需要在项目的/public 目录下正确设置.htaccess 文件。默认情况下,Laravel 附带一个。您只需要告诉apache2 阅读该文件并遵守规则即可。

    首先通过运行启用mod_rewrite

    sudo a2enmod rewrite
    

    然后转到位于/etc/apache2/apache2.confapache2 配置文件并找到显示<Directory /var/www/html> 的部分(或您的Laravel 项目public 文件夹的路径)并添加/编辑以下行:

    AllowOverride All
    

    使用sudo service apache2 restart重新启动apache2

    【讨论】:

      猜你喜欢
      • 2020-12-06
      • 1970-01-01
      • 2019-08-28
      • 2020-08-06
      • 2019-08-31
      • 2021-05-05
      • 1970-01-01
      相关资源
      最近更新 更多