2 years ago

#69125

test-img

Dula

"/" route in Symfony shows the actual files in the server

I have a Symfony 5.3 project in my local machine and I am using XAMPP. I have set up my project using vhosts and my local URL is "http://www.myproject2.local/".

The project is running fine when I access the URL "http://www.myproject2.local/login" and it loads the views/pages after the login but when I access the URL "http://www.myproject2.local/" it lists the project files like below.

enter image description here

Following is my login method in the SecurityController.

/**
 * @Route("/", name="app_home")
 * @Route("/login", name="app_login")
 */
public function login(AuthenticationUtils $authenticationUtils): Response
{
     if ($this->getUser()) {
         return $this->redirectToRoute('app_admin_dashboard');
     }

    // get the login error if there is one
    $error = $authenticationUtils->getLastAuthenticationError();
    // last username entered by the user
    $lastUsername = $authenticationUtils->getLastUsername();

    return $this->render('security/login.html.twig', [
        'last_username' => $lastUsername,
        'error' => $error,
        'loginPage' => true
    ]);
}

Since I have an Apache server in my XAMPP I have used a .htaccess file to rewrite the URL and remove public/index.php/ from the URL.

Following is the code I have in the .htaccess file.

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ public/index.php/$1 [L]
</IfModule>

I am sure I have done or set up something wrong, but have no idea what. What I want to achieve is when someone visits the URL "http://www.myproject2.local/" to load the login page instead of all the files on the website.

Can someone please point me in the correct direction or tell me what I have done wrong?

php

.htaccess

xampp

xampp-vm

0 Answers

Your Answer

Accepted video resources