.htaccess - Why does htaccess rewriteRule not work and returns 404 not found
问题描述
I'm trying to make simple image cacher
Idea is to request http://example.com/folder/00filename
which is translated by .htaccess
to http://example.com/folder/00/00filename
.
If it does not exist, then call .php
script.
PS: There is also ?url=
part http://example.com/folder/00filename?url=http://s2.example.com/imagetocache.png
which is needed by index.php
RewriteEngine on
RewriteBase /imagecache/
RewriteCond %{DOCUMENT_ROOT}/imagecache/$1/$2/$2$3 !-f #works
RewriteRule ^(.*)/(.{2})(.*)$ index.php [QSA,L] #works
RewriteCond %{DOCUMENT_ROOT}/imagecache/$1/$2/$2$3 -f #works
#RewriteRule ^(.*)/(.{2})(.*)$ dump.php [QSD,L] #works (if uncommented)
RewriteRule ^(.*)/(.{2})(.*)$ $1/$2/$2$3 [QSD,L] #does not work - returns 404 not found
Also, why these do not work? It's like ENV:REWRITEBASE
is empty for RewriteCond but not for RewriteRule
RewriteCond %{DOCUMENT_ROOT}/%{ENV:REWRITEBASE}/$1/$2/$2$3 -f
RewriteCond %{ENV:REWRITEBASE}$1/$2/$2$3 -f
RewriteCond /$1/$2/$2$3 -f
RewriteCond $1/$2/$2$3 -f
解决方案
推荐阅读
- webpack - 使用电子 ipc 时停止的电子锻造符合渲染器代码
- c++ - C++ `using {var}` 不是 {child class} 的成员 - 在 MSVC 或 Clang 中使用`std::deque` 时
- asp.net-core - ASP.NET Core:重定向问题
- discord - 我正在制作一个不和谐的机器人......我一直收到这个错误
- javascript - 使用 JavaScript 哈希密码认证?
- path - 自动删除不存在的路径变量
- node.js - 如何在构建和开发中的本地主机服务器上运行电子
- arrays - 使用 Select 的 DataTable 中的 Double(,) 而不是 Double()()
- maven - 如何检查安装在 Drools 机器中的 maven
- python - 我有个问题。使用 RPI 和 CAT.M1(BG96) 在 aws iot MQTT 上使用 AT COMMAND 进行通信