如何使用 zf2 的子域路由?
How to use subdomain route with zf2 ?
我正在尝试在 zf2 中使用子域路由,但出现 dns 错误。我添加了这样的路线:
'testSubDomain' => array(
'type' => 'Hostname',
'options' => array(
'route' => ':blog.mydomain.net',
),
'may_terminate' => false,
'child_routes' => array(
'home' => array(
'type' => 'Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Solution',
'action' => 'testSubdomain'
)
)
)
)
),
我已经创建了 apache vhost,/etc/apache2/sites-enabled/000-default.conf 的配置如下:
<VirtualHost *:80>
ServerName mydomain.net
ServerAlias mydomain.net
DocumentRoot /var/www/beta/public
<directory /var/www/beta/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</directory>
<Directory /var/www/beta/public>
Options -Indexes
Require all granted
</Directory>
</VirtualHost>
----------
Some other vhost
-----------
当我转到 blog.mydomain.net 时,它显示找不到服务器 DNS 地址。我没有在 000-default.conf 中为 subdmoain 定义任何虚拟主机,所以它应该使用第一个。我也为子域添加了一条 A 记录,但它也不起作用。
本题贴出的答案是正确的,需要注意的地方。不要为您的子域创建 Vhost,但您的子域应指向服务器。如果您为子域创建虚拟主机,那么它将遵循应用程序模块配置路由并向您显示主页。
'testSubDomain' => array(
'type' => 'Hostname',
'options' => array(
'route' => 'blog.mydomain.net',
),
'may_terminate' => false,
'child_routes' => array(
'home' => array(
'type' => 'Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Solution',
'action' => 'testSubdomain'
)
)
)
)
),
当你去blog.mydomain.net它会告诉你testSubdomain函数的内容。 无需为子域创建任何虚拟主机。
我正在尝试在 zf2 中使用子域路由,但出现 dns 错误。我添加了这样的路线:
'testSubDomain' => array(
'type' => 'Hostname',
'options' => array(
'route' => ':blog.mydomain.net',
),
'may_terminate' => false,
'child_routes' => array(
'home' => array(
'type' => 'Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Solution',
'action' => 'testSubdomain'
)
)
)
)
),
我已经创建了 apache vhost,/etc/apache2/sites-enabled/000-default.conf 的配置如下:
<VirtualHost *:80>
ServerName mydomain.net
ServerAlias mydomain.net
DocumentRoot /var/www/beta/public
<directory /var/www/beta/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</directory>
<Directory /var/www/beta/public>
Options -Indexes
Require all granted
</Directory>
</VirtualHost>
----------
Some other vhost
-----------
当我转到 blog.mydomain.net 时,它显示找不到服务器 DNS 地址。我没有在 000-default.conf 中为 subdmoain 定义任何虚拟主机,所以它应该使用第一个。我也为子域添加了一条 A 记录,但它也不起作用。
本题贴出的答案是正确的,需要注意的地方。不要为您的子域创建 Vhost,但您的子域应指向服务器。如果您为子域创建虚拟主机,那么它将遵循应用程序模块配置路由并向您显示主页。
'testSubDomain' => array(
'type' => 'Hostname',
'options' => array(
'route' => 'blog.mydomain.net',
),
'may_terminate' => false,
'child_routes' => array(
'home' => array(
'type' => 'Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Solution',
'action' => 'testSubdomain'
)
)
)
)
),
当你去blog.mydomain.net它会告诉你testSubdomain函数的内容。 无需为子域创建任何虚拟主机。