首页 > 新装的symfony,本地正常,但是远程访问不行,怎么回事?

新装的symfony,本地正常,但是远程访问不行,怎么回事?

根据官网的教程学习symfony,建立第一个页面,就那那个luky/number的页面。代码如下:

// src/AppBundle/Controller/HelloController.php
namespace AppBundle\Controller;

use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class HelloController
{
    /**
     * @Route("/hello/{name}", name="hello")
     */
    public function indexAction($name)
    {
        return new Response('<html><body>Hello '.$name.'!</body></html>');
    }

}

这个页面通过http://localhost:8000/lucky/number,或者域名http://mydomain.com/lucky/number都可以访问,很正常,但是他第二个例子,生成json数据的额,却只能在本地访问,不能通过域名访问,下面是代码:

// src/AppBundle/Controller/LuckyController.php
namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;

class LuckyController
{
    
    /**
     * @Route("/api/lucky/number")
     */
    public function apiNumberAction()
    {
        $data = array(
            'lucky_number' => rand(0, 100),
        );

        return new Response(
            json_encode($data),
            200,
            array('Content-Type' => 'application/json')
        );
    }
}

通过域名访问会提示:

Oops! An Error Occurred
The server returned a "404 Not Found".
Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.

不知道是什么原因,Rewrite也已经开启了,别的代码都没有动,一步一步都是按照教程来的。会是哪里的问题呢?

【热门文章】
【热门文章】