Symfony allow files access in Resources folder .htaccess

时间:2017-04-06 17:01:02

标签: php .htaccess symfony

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 个答案:

答案 0 :(得分:1)

问题是服务器的DocumentRoot指向/web目录,/app目录超出范围。也许你可以使用别名解决它:

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>

使用alias时,必须使用别名为路由添加前缀到资源。

例如,获取resoource test.jpg位于:

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

您的请求应该是:

http://yourServerName/export/test.jpg

此类路由的问题是Symfony路由无法管理它,因为服务器范围不足,但您可以使用主机匹配,请参阅此问题:

Routing prefix as follows the Virtual Host

如果使用别名,请记住启用别名模块(如果已禁用)。

希望它有所帮助。