.htaccess正在破坏上载的文件路径


.htaccess breaking file path for uploads

我有一个Symfony 2项目,我不得不使用.htaccess配置来隐藏前端文件和web目录,但在这个过程中,这意味着我无法访问我创建的公共上传文件夹。有没有办法为该路由创建符号链接或异常?

这是我当前的.htaccess

   <IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On
    # Explicitly disable rewriting for front controllers
    RewriteRule ^/web/app_dev.php - [L]
    RewriteRule ^/web/app.php - [L]
    # Fix the bundles folder
    RewriteRule ^bundles/(.*)$ /web/bundles/$1  [QSA,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    # Change below before deploying to production
    RewriteRule ^(.*)$ /web/app.php [QSA,L]
    #RewriteRule ^(.*)$ /web/app_dev.php [QSA,L]
</IfModule>

提前感谢!

您可以添加一个异常,以避免像禁用前端控制器重写一样重写某个文件夹。只需添加RewriteRule ^path-to-folder/.* - [L]即可访问文件夹路径中的文件。

您可以创建一个异常,就像您已经做过的那样:

#disable redirecting for all the files in /web/upload dir
RewriteRule ^web/upload/.* - [L]

将其放入.htaccess的开头,它将在重定向发生之前停止处理。有一件事,我不明白,为什么在开头有一个额外的斜杠:^/web。因为.htaccess条件中应该省略第一个斜杠。