我已经写在.htaccess文件中这样的规则:的Apache的.htaccess文件重定向
# Rewrite super sized ciim5 images to large
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ciim5/([0-9]+)/([0-9]+)/super_000000\.jpg$ /ciim5/$1/$2/large_000000.jpg [NC,L,R=301]
它应该做的是,当被请求的路径/ciim5/123/456/super_000000.jpg
,应该301重定向到相同的路径,但服务large_000000.jpg
代替。 super_0000000.jpg
和large_000000.jpg
是该服务器上的实际物理文件(实际上我们希望隐藏超大尺寸的图像,并将它们重定向到大)
我在本地主机上试过这个规则(Apache/2.4.7(Ubuntu) )和它的工作(其余的.htaccess文件是相同的生产之一)。但是当我将它上传到生产服务器(Apache/2.4.18(Ubuntu))时,它根本没有做任何事情。但以前存在的重写可以工作(= mod_rewrite已启用)。我已经确保.htaccess文件在生产站点上更新(它是),甚至创建了一个test.html文件并在浏览器中打开它,以确保我正在将文件上传到正确的目录中。
我现在坐在这里抓我的头,有人可以告诉我为什么上述不生产的服务器上,如何让它做重定向?
编辑: 路径/ciim5
实际上设置为不在Web根目录中的目录的别名。那么这可能是web根目录中的.htaccess文件没有被读取的情况?我应该将.htaccess文件放在/ ciim5目录中吗?
编辑2: 启用日志说明这一点:
[Thu Dec 01 10:05:48.444800 2016] [rewrite:trace1] [pid 4572] mod_rewrite.c(476): [client *:33116] * - - [*.org.uk/sid#7f767fb185c8][rid#7f767fa9c0a0/initial] pass through /ciim5/295/491/super_000000.jpg
[Thu Dec 01 10:05:48.445015 2016] [rewrite:trace3] [pid 4572] mod_rewrite.c(476): [client *:33116] * - - [*.org.uk/sid#7f767fb185c8][rid#7f767fa9c0a0/initial] [perdir /static-media/] strip per-dir prefix: /static-media/295/491/super_000000.jpg -> 295/491/super_000000.jpg
[Thu Dec 01 10:05:48.445113 2016] [rewrite:trace3] [pid 4572] mod_rewrite.c(476): [client *:33116] * - - [*.org.uk/sid#7f767fb185c8][rid#7f767fa9c0a0/initial] [perdir /static-media/] applying pattern '^(ciim5/[0-9]+/[0-9]+/)super_000000\\.jpg$' to uri '295/491/super_000000.jpg'
[Thu Dec 01 10:05:48.445204 2016] [rewrite:trace1] [pid 4572] mod_rewrite.c(476): [client *:33116] * - - [*.org.uk/sid#7f767fb185c8][rid#7f767fa9c0a0/initial] [perdir /static-media/] pass through /static-media/295/491/super_000000.jpg
这是什么 “带每个目录前缀” 的事情吗?似乎它删除ciim5或静态媒体(ciim5别名的实际文件夹)。所以我应该从我的rewriterule中删除ciim5
部分?
检查重写模块的调试日志([LogLevel](https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#logging))。在两台服务器上。你看到有什么不同吗? –
@DavidDuponchel检查**编辑2 **,谢谢! – Beebee