dsaeyrq451928
2017-04-06 17:01
浏览 78
已采纳

Symfony允许在Resources文件夹.htaccess中访问文件

I need to open access to the following folder for everyone:

C:\xampp\htdocs\myapp\app\Resources\export

but I get 403 Forbidden error. I tried many variants but still no luck. My .htaccess which is located at

C:\xampp\htdocs

is as follows:

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On

# Explicitly disable rewriting for front controllers
RewriteRule ^app_dev.php - [L]
RewriteRule ^app.php - [L]

# Fix the bundles folder
RewriteRule ^bundles/(.*)$ /myapp/web/bundles/$1  [QSA,L]
RewriteRule ^js/(.*)$ /myapp/web/js/$1  [QSA,L]
RewriteRule ^css/(.*)$ /myapp/web/css/$1  [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /myapp/web/app.php [QSA,L]
RewriteRule (.*) $1 [E=SYMFONY_ENV:prod]

Any ideas would be welcome. Thank you.

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongwo5110 2017-04-06 19:20
    已采纳

    The problem is that DocumentRoot of your server is pointing to /web directory and /app directory is out of scope. Maybe you can solve it using an alias:

    Alias /export "C:/xampp/htdocs/myapp/app/Resources/export"
    <Directory "C:/xampp/htdocs/myapp/app/Resources/export">
        Options Indexes
        AllowOverride None
        Require all granted
    </Directory>
    

    When using alias you must to prefix the route to the resource with the alias name.

    For example for getting the resoource test.jpg located in:

    C:/xampp/htdocs/myapp/app/Resources/export/test.jpg
    

    Your request should be like:

    http://yourServerName/export/test.jpg
    

    The problem of this type of routes is that Symfony routing can't managed it because there are out of server scope, but you can use host-matching, see this question:

    Routing prefix as follows the Virtual Host

    If you use alias remember enable alias module if it is disabled.

    Hope it helps.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题