dsfphczao23473056 2017-09-05 09:26 采纳率: 100%
浏览 75
已采纳

Symfony生产路由问题

I have configured my virtual host (apache2) in this way:

<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>

And i can see homepage and assets but not other routes.

if i change document root to:

<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>

Now i can see all routes but not assets...

How can i setup the virtual host to see all routes and assets?

  • 写回答

1条回答 默认 最新

  • douyi4912 2017-09-05 09:55
    关注
    <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>
    

    also check 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 document Configuring a Web Server

    also dumps all routes into apache by using this comment php app/console router:dump-apache

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?