.htaccess打破上传的文件路径

时间:2013-07-18 20:33:46

标签: php apache .htaccess symfony config

我有一个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>

提前致谢!

2 个答案:

答案 0 :(得分:1)

您可以添加例外以不重写某个文件夹,就像禁用前控制器重写一样。只需添加RewriteRule ^path-to-folder/.* - [L]即可使用它们,并且可以访问路径到文件夹中的文件。

答案 1 :(得分:0)

您可以像以前一样创建例外:

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

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