简体   繁体   中英

Issue when deploying Symfony project to prod server

I'm new to Symfony and I have encountered an issue where my routes return a 404 error. Everything is working fine on my dev environment but I don't know how to deploy my project on the prod server. I've probably missed a step somewhere.

So here is one of my controller named HomeController :

<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class HomeController extends AbstractController
{
    #[Route('/', name: 'home')]
    public function index(): Response
    {
        return $this->render('home/index.html.twig');
    }


    #[Route('/pc', name: 'home_pc')]
    public function pc(): Response
    {
        return $this->render('home/pc.html.twig');
    }

When I do this following command php bin/console debug:router --show-controllers . The console prints the following so I guess Symfony knows my different routes.

 --------- -------- -------- ------ ------ ----------------------------------------
  Name      Method   Scheme   Host   Path   Controller
 --------- -------- -------- ------ ------ ----------------------------------------
  home      ANY      ANY      ANY    /      App\Controller\HomeController::index()
  home_pc   ANY      ANY      ANY    /pc    App\Controller\HomeController::pc()
 --------- -------- -------- ------ ------ ----------------------------------------

And then, when I try to access mywebsite.com/pc for example, it just gives me a blank page and a 404 error .

Can anyone help me with my issue? Maybe you'd need another file to see what's wrong?

Try put this .htaccess content in public_html directory

RewriteEngine On
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]

Even if it works it shouldn't be done this way, so think of it as a temporary solution

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM