2017-09-05 109 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服務器。現在工作! –