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

时间:2018-12-27 18:04:30

标签: php symfony

我正在研究symfony-demo项目,但我面临一个疑问:此项目已配置为使索引重定向到路由/可以想象是从语言环境获取的。事实是,我想更改设置索引时重定向到的路由:www.mywebsite.com重定向到我想要的路由,我不知道该如何实现,这里我保留index.php:< / p>

<?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);

我还想知道演示如何在我搜索但没有找到时重定向到/ es。

1 个答案:

答案 0 :(得分:0)

请勿触摸public / index.php文件... 有一个与“ /”路由匹配的控制器是您可以重定向的一种选择!!!

class IndexController extends AbstractController
{
    /**
     * @Route("/", name="index")
     */
    public function index()
    {
         return $this->redirectToRoute('the_route_you_want');
    }
}