0

我在本地机器上有一个 Symfony 5.3 项目,我正在使用 XAMPP。我已经使用虚拟主机设置了我的项目,我的本地 URL 是“http://www.myproject2.local/”。

当我访问 URL“http://www.myproject2.local/login”时,项目运行良好,它在登录后加载视图/页面,但当我访问 URL“http://www.myproject2.local/”时" 它列出了如下所示的项目文件。

在此处输入图像描述

以下是我在 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
    ]);
}

由于我的 XAMPP 中有一个 Apache 服务器,因此我使用了一个.htaccess文件来重写 URL 并public/index.php/从 URL 中删除。

以下是我在.htaccess文件中的代码。

<IfModule mod_rewrite.c>
    RewriteEngine On

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

我确定我做错了或设置了错误,但不知道是什么。我想要实现的是当有人访问 URL“http://www.myproject2.local/”来加载登录页面而不是网站上的所有文件时。

有人可以指出我正确的方向或告诉我我做错了什么吗?

4

0 回答 0