2017-09-05 112 views
0

我已经以这种方式配置我的虚拟主机(apache2的):Symfony的生产路由问题

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    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 [email protected] 
    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> 

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

我怎样才能设置虚拟主机看到所有路线和资产?

+0

这个gonfig在windows上? –

+0

在Ubuntu 16.04上 –

+0

当您尝试使用第一个配置访问其他路由时会发生什么? –

回答

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> 

还要检查网/的.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> 

鲽文件Configuring a Web Server

也通过此评论PHP应用程序/台路由器转储所有路由到阿帕奇:翻斗阿帕奇

+0

谢谢我在本教程中使用虚拟主机(第二个):配置Web服务器。现在工作! –