2017-10-16 22 views
1

我有我的yii2應用程序高級項目的單域配置。在配置工作正常之前,但現在我無法管理任何圖像文件的鏈接。當我試圖通過http://{domain}/icons/logo.svg鏈接下載文件,我有404錯誤:404找不到文件鏈接在Yii2應用程序 - 先進的單域配置

Not Found 

The requested URL /icons/logo.svg was not found on this server. 

http://{domain}/frontend/web/icons/logo.svg作品。 文件存在於顯示文件夾中。如何糾正項目中的apache配置文件以使用短鏈接。

這裏我的配置:

  • 阿帕奇:

    <VirtualHost *:80> 
        ServerName test.dev 
    
        ServerAdmin [email protected] 
        DocumentRoot /home/user/Projects/test-app/ 
    
        <Directory /home/user/Projects/test-app/> 
         Require all granted 
         AllowOverride All 
        </Directory> 
    </VirtualHost> 
    
  • 基地.htacces

    Options -Indexes 
    IndexIgnore */* 
    
    Options +SymLinksIfOwnerMatch 
    
    <IfModule mod_rewrite.c> 
    RewriteEngine on 
    
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ 
    RewriteRule ^(.*)$ http://%1/$1 [L,R=301] 
    
    RewriteRule ^admin(.{2,})?(/)?$ /backend/web/$1 [L,PT] 
    RewriteRule ^([^/].*)?$ /frontend/web/$1 
    </IfModule> 
    
  • 前端.htacces

    Options -Indexes 
    
    <IfModule mod_rewrite.c> 
    RewriteEngine on 
    
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule . index.php 
    </IfModule> 
    
    DirectoryIndex index.php 
    
    • 在配置文件中frontend\config\main.php也使:
'components' => [ 
    'request' => [ 
     'csrfParam' => '_csrf-frontend', 
     'baseUrl' => '', 
    ], 
    'urlManager' => [ 
     'enablePrettyUrl' => true, 
     'showScriptName' => false, 
     'rules' => [ 
      '' => 'site/index', 
      'sitemap' => 'sitemap/index', 
     ], 
    ], 

回答

1

我發現這個問題。 Apache擁有自己的圖標iconshttps://www.electrictoolbox.com/apache-icons-directory/

所以,如果你想使用的圖標文件夾的名稱,你應該把它放在subdirecotory,例如img/icons/...:這別名只能在服務器配置在這裏描述/etc/apache2/mods-available/alias.conf

發行覆蓋。或者使用另一個目錄名稱。

0

此行添加到您的.htaccess文件:

RewriteRule ^icons/(.*)$ frontend/web/icons/$1 [L] 
+0

Sardor Dushamov,你的變種不工作了。 除此之外,在問題配置中描述在我的電腦上的其他yii2項目中工作正常。也許,有些錯誤更一般? – Oleg

相關問題