我目前工作的公司拥有3年以上基于symfony 2.8的现场网站。最近它被部署用于测试新客户。原始图像可以在html中访问,例如" /bundles/bundlename/images/image.png"。
在客户服务器上,整个事情都在子文件夹下,因此图像网址应该像" /d2s/bundles/bundlename/images/image.png"。 我们在项目的web目录中有一个.htaccess文件,如下所示:
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
FollowSymLinks On
RewriteRule /?bundles/(.*)$ /d2s/bundles/$1 [NC,R=301,L]
# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the app.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
[,,,]
所有其他部分工作正常,在apache conf的虚拟主机中,AllowOverride设置为All。但这个重写的网址只是不起作用,就像它根本不存在一样。
知道什么是错的吗?
答案 0 :(得分:0)
设置正确的RewriteBase。不要使用/
启动内部RewriteRule模式或替换。如果您要坚持使用RewriteBase等效的自动确定,它应该先于所有其他规则。