0

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?

yivi
  • 42,438
  • 18
  • 116
  • 138
Dula
  • 1,276
  • 5
  • 14
  • 23
  • 1
    You are pointing your webserver to the root of your project, you should point it to `public`. – yivi Jan 19 '22 at 09:59
  • @yivi - thank you for the comment but I am planning to host this web application on a public server. In there I have to place all my files inside ``public_html`` folder and I do not have the option to point to Symfony ``public`` flder. Is there a solution for this? (I was trying to replicate that situation in my local) – Dula Jan 21 '22 at 21:16

0 Answers0