[英]how to route symfony urls and remove front controller from url
i ve tried some methods to route my url我尝试了一些方法来路由我的 url
rootdirectory/src/Simplex/app.php
require __DIR__.'/../vendor/autoload.php';
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
$routes = new RouteCollection();
$routes->add('ip',
new Route('/ip',
[
'IPAddress' => "52.77.50.64",
'_controller' => 'Controller\Controller::getIPResponse',
]
)
);
$routes->add('home',
new Route('/',
[
'IPAddress' => "52.77.50.64",
'_controller' => 'Controller\Controller::getIPResponse',
]
)
);
and和
rootdirectory/front.php
require __DIR__.'/vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
$globals = (Request::createFromGlobals())->getPathInfo();
$request = Request::create($globals);
$routes = include __DIR__ . '/src/app.php';
$container = include __DIR__ . '/src/container.php';
$response = $container->get('framework')->handle($request);
$response->send();
when i try to access myDomain.com/front.php/ip it works but when i try to use myDomain.com/ip it doesnt work.当我尝试访问 myDomain.com/front.php/ip 时它可以工作,但是当我尝试使用 myDomain.com/ip 时它不起作用。
I also worked on my .conf file and it pointing to my front controller.我还处理了我的 .conf 文件,它指向我的前端控制器。 ie if i go to myDomain.com/ it works .
即如果我去 myDomain.com/ 它工作。
I also checked symfony routing doc but i think they didnt give the solution for this.我还检查了 symfony 路由文档,但我认为他们没有为此提供解决方案。
I havent used .htaccess file我没有使用过 .htaccess 文件
The solution lies in xyz.conf file .解决方案在于 xyz.conf 文件。 i used fallbackresources /front.php and it worked fine.
我使用了 fallbackresources /front.php 并且效果很好。 Similar to the code below
类似于下面的代码
<VirtualHost *:80>
ServerName foo.example.com
DocumentRoot /var/www/html
DirectoryIndex index.php
FallbackResource /index.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.