2017-07-06 27 views
0

我目前正在建設有BazingaHateoasBundle和Symfony的2.7Symfony的使用錯誤域,以生成絕對URL

這裏,哈爾HATEOAS的RESTful API是我的配置文件:

MyBundle\Entity\MyEntity: 
    relations: 
    - rel: self 
     href: 
     route: get_myentity 
     parameters: 
      id: expr(object.getId()) 
     absolute: true 

在本地,我有一個Apache與虛擬主機和我的反應是正確的:

{ 
    "id":1, 
    "_links": { 
     "self": { 
      "href": "http://dev.myvhost/api/myentity/1" 
     } 
} 

在我開發服務器,我有這樣的事情:

{ 
    "id":1, 
    "_links": { 
     "self": { 
      "href": "http://my-machine-name/api/myentity/1" 
     } 
} 

我不想my-machine-name,而是my-server-name.com

而我的服務器Apache的配置是這樣的:

ServerName my-server-name.com 
Alias "/api" "/var/www/api/web" 

<VirtualHost *:80> 
    <Directory /var/www/api/web> 
     AllowOverride None 
     Require all granted 
     Allow from All 

     <IfModule mod_rewrite.c> 
      Options -MultiViews 
      RewriteEngine On 
      RewriteCond %{REQUEST_FILENAME} !-f 
      RewriteRule ^(.*)$ /api/app.php [QSA,L] 
     </IfModule> 
    </Directory> 

    <Directory /var/www/api/web/bundles> 
     <IfModule mod_rewrite.c> 
      RewriteEngine Off 
     </IfModule> 
    </Directory> 
    ErrorLog /var/log/httpd/api_error.log 
    CustomLog /var/log/httpd/api_access.log combined 
</VirtualHost> 

是否有配置Symfony的,這樣我也許可以直接設置在主機的方法嗎?

回答

0

我認爲你錯過了這裏的一步。那就是你需要將my-server-name.com添加到(系統的)主機文件。

這是另一個有用的話題鏈接:Symfony 2 on virtual hosts