dongnaoxia0927 2018-12-27 18:04
浏览 70
已采纳

index.php到哪个路由重定向?

I am studying the symfony-demo project and I am faced with a doubt: This project is configured so that the index redirects to the route / is imagined to be taken from the locale. The fact is that I want to change the route to which the index redirects when it is set: www.mywebsite.com redirects to the route I want, I do not know how to achieve this, here I leave my index.php:

<?php

use App\Kernel;
use Symfony\Component\Debug\Debug;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpFoundation\Request;

require __DIR__.'/../vendor/autoload.php';

// The check is to ensure we don't use .env in production
if (!isset($_SERVER['APP_ENV'])) {
    if (!class_exists(Dotenv::class)) {
         throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add   "symfony/dotenv" as a Composer dependency to load variables from a .env   file.');
    }
(new Dotenv())->load(__DIR__.'/../.env');
}

$env = $_SERVER['APP_ENV'] ?? 'dev';
$debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env));

if ($debug) {
    umask(0000);

    Debug::enable();
}

if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? false) {
    Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}

if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? false) {
    Request::setTrustedHosts(explode(',', $trustedHosts));
}

$kernel = new Kernel($env, $debug);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

I would also like to know how the demo redirects to /es as I searched and did not find.

  • 写回答

1条回答 默认 最新

  • dongxueji2838 2018-12-28 11:18
    关注

    Don't touch the public/index.php file ... Have a Controller which match with the "/" route's is one option where you can redirect!!!

    class IndexController extends AbstractController
    {
        /**
         * @Route("/", name="index")
         */
        public function index()
        {
             return $this->redirectToRoute('the_route_you_want');
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置