【问题标题】:Symfony production routing issueSymfony 生产路由问题
【发布时间】:2018-02-13 13:06:00
【问题描述】:

我以这种方式配置了我的虚拟主机(apache2):

<VirtualHost *:80>
    ServerAdmin info@mysite.com
    ServerName mysite.com
    ServerAlias www.mysite.com
    DocumentRoot /var/www/mysite.com/public_html/web
    <Directory /var/www/mysite.com/public_html/web>
      Require all granted
      AllowOverride All
      Order Allow,Deny
      Allow from All
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

我可以看到主页和资产,但看不到其他路线。

如果我将文档根目录更改为:

<VirtualHost *:80>
    ServerAdmin info@mysite.com
    ServerName mysite.com
    ServerAlias www.mysite.com
    DocumentRoot /var/www/mysite.com/public_html/web/app.php
    <Directory /var/www/mysite.com/public_html/web/app.php>
      Require all granted
      AllowOverride All
      Order Allow,Deny
      Allow from All
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

现在我可以看到所有路线但看不到资产...

如何设置虚拟主机以查看所有路由和资产?

【问题讨论】:

  • 这个 gonfig 在 windows 上?
  • 在 Ubuntu 16.04 上
  • 当您尝试使用第一个配置访问其他路由时会发生什么?
  • 在此服务器上找不到请求的 URL /azienda。

标签: php symfony routing virtualhost symfony-2.3


【解决方案1】:
<VirtualHost *:80>
   ServerName test.io
   DocumentRoot "your_project_path/web"
   RewriteRule ^/?(.*) http://test.io/app.php$1 [R,L]
   <Directory "your_project_path/web">
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Order Allow,Deny
      Allow from all
      Require all granted
      RewriteEngine On
      RewriteCond %{REQUEST_FILENAME} -s [OR]
      RewriteCond %{REQUEST_FILENAME} -l [OR]
      RewriteCond %{REQUEST_FILENAME} -d
      RewriteRule ^.*$ - [NC,L]
      RewriteRule ^(.*) /app.php [NC,L]
   </Directory>
</VirtualHost>

同时检查 web/.htaccess

   DirectoryIndex app.php
   <IfModule mod_negotiation.c>
          Options -MultiViews
   </IfModule>

   <IfModule mod_rewrite.c>
         RewriteEngine On
         RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
         RewriteRule ^(.*) - [E=BASE:%1]

         # Sets the HTTP_AUTHORIZATION header removed by apache
         RewriteCond %{HTTP:Authorization} .
         RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
         RewriteCond %{ENV:REDIRECT_STATUS} ^$
         RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
         RewriteCond %{REQUEST_FILENAME} -f
         RewriteRule .? - [L]
         RewriteRule .? %{ENV:BASE}/app_dev.php [L]
   </IfModule>

   <IfModule !mod_rewrite.c>
        <IfModule mod_alias.c>
              RedirectMatch 302 ^/$ /app.php/
              # RedirectTemp cannot be used instead
         </IfModule>
   </IfModule>

asper 文档Configuring a Web Server

还通过使用此注释将所有路由转储到 apache php app/console router:dump-apache

【讨论】:

  • 感谢我在本教程中使用了虚拟主机(第二台):配置 Web 服务器。现在有效!
猜你喜欢
  • 2017-09-10
  • 2011-05-20
  • 1970-01-01
  • 1970-01-01
  • 2013-01-18
  • 2011-09-12
  • 2011-04-18
相关资源
最近更新 更多