在找不到具有单域配置的Yii2 app-advanced的文件链接404

时间:2017-10-16 20:49:53

标签: php apache .htaccess yii2

我在yii2 app-advanced项目中有一个域配置。在配置工作正常之前,但现在我无法管理任何图像文件的链接。当我尝试按var elemarray = []; elemarray.push($('#elem1').text()); elemarray.push($('#elem2').text()); alert(elemarray[0]); if ($.inArray($('#elem1').text(), elemarray) !== -1) { alert('Found'); } else { alert('Not found'); } 链接下载文件时,出现404错误:

http://{domain}/icons/logo.svg

Not Found The requested URL /icons/logo.svg was not found on this server. 有效。 文件存在于显示文件夹中。如何纠正项目中的apache配置文件以使用短链接。

这是我的配置:

  • 阿帕奇:

    http://{domain}/frontend/web/icons/logo.svg
  • base <VirtualHost *:80> ServerName test.dev ServerAdmin test@test.ua 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

2 个答案:

答案 0 :(得分:1)

我发现了问题。 Apache拥有自己的目录icons。此别名只能在/etc/apache2/mods-available/alias.conf

的服务器配置上覆盖

此处描述的问题:https://www.electrictoolbox.com/apache-icons-directory/

因此,如果您想使用图标文件夹名称,则应将其放在子目录中,例如img/icons/...。或者使用其他目录名称。

答案 1 :(得分:0)

将此行添加到.htaccess文件中:

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