【发布时间】:2017-12-10 11:32:53
【问题描述】:
我目前正在使用 BazingaHateoasBundle 和 Symfony 2.7 构建 Hal 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 以便我可以直接设置主机?
【问题讨论】: