Symfony2 Vhost 配置

Symfony2 Vhost 配置

我是 Symfony2 的新手,正在关注EnsJobeet 教程。我的VirtualHost配置如下:

<VirtualHost *:80>
    ServerName jobeet.local
    DocumentRoot /var/www/ensjobeet/web/
    DirectoryIndex app.php
    ErrorLog /var/log/apache2/jobeet-error.log
    CustomLog /var/log/apache2/jobeet-access.log combined
    <Directory "/var/www/ensjobeet/web/">
        AllowOverride All
        Allow from All
    </Directory>
</VirtualHost>

当我向 jobeet.local/app_dev.php/job/ 发出请求时,我得到了作业页面,当我向 jobeet.local/app.php/job/ 发出请求时,我得到了作业页面。但是向 jobeet.local/job/ 发出请求时,会出现 404 错误The requested URL /job/ was not found on this server.

我原本以为请求 jobeet.local/ 和 jobeet.local/app.php/ 应该是等效的,但是它们似乎并不等效,那么我在环境配置的其他方面是否出了问题?

答案1

这里prod 和 dev vhosts 的示例

# Symfony 2 : monapp.dev
<virtualHost *:80>
  ServerName monapp.dev
  DocumentRoot /data/www/MonApp/web/

    <Directory "/data/www/MonApp/web">
      DirectoryIndex app_dev.php
      Options -Indexes FollowSymLinks SymLinksifOwnerMatch
      AllowOverride None
      RewriteEngine On
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^(.*)$ app_dev.php [QSA,L]
    </Directory>
</VirtualHost>

# Symfony 2 : monapp.prod
<VirtualHost *:80>
  ServerName monapp.prod
  DocumentRoot /data/www/MonApp/web/

    <Directory "/data/www/MonApp/web">
       DirectoryIndex app.php
       Options -Indexes FollowSymLinks SymLinksifOwnerMatch
       AllowOverride All
       Allow from All
    </Directory>
</VirtualHost>

答案2

mod_rewrite 已安装但未启用。我真傻!!

答案3

两个文件的组合+(@Bendihossan@艾玛)在这里工作......

<VirtualHost *:80>
    ServerName symfony2-7-9.dev
    DocumentRoot /var/www/symfony2-7-9/web/
    DirectoryIndex app.php
    ErrorLog ${APACHE_LOG_DIR}/symfony2-7-9-error.log
    CustomLog ${APACHE_LOG_DIR}/symfony2-7-9-custom.log combined
    <Directory "/var/www/symfony2-7-9/web/">
        Options -Indexes FollowSymLinks SymLinksifOwnerMatch
        AllowOverride None
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ app_dev.php [QSA,L]
    </Directory>
</VirtualHost>

答案4

设置虚拟主机后,将以下代码放入 web/.htaccess 文件中

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    #<IfModule mod_vhost_alias.c>
    #    RewriteBase /
    #</IfModule>

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ app_dev.php [QSA,L]
</IfModule>

相关内容