【发布时间】:2014-07-06 01:54:41
【问题描述】:
我想检查缓存文件夹中是否不存在文件,而不是将其重新连接到 php 文件。
RewriteCond %{DOCUMENT_ROOT}/cache/$0 !-f [NC]
RewriteRule ^([^.]+\.(jpg|png|gif|css|js))$ include/cache/optimizer.php?file=$1&type=$2&c=$0 [L,QSA,NC]
eg1 : example.com/images/logo.jpg 从 example.com/cache/images/logo.jpg 检查
eg2 :example.com/images/user/user1.jpg 从example.com/cache/user/user1.jpg检查
eg3 : example.com/css/style.css 从 example.com/cache/css/style.css 中检查
请帮帮我。
谢谢。
我的 htaccess 代码:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# Admin area
RewriteRule ^admin(.*) admin$1 [L]
# Rule for compression images and scripts
RewriteCond %{DOCUMENT_ROOT}/cache%{REQUEST_URI} !-f [NC]
RewriteRule ^([^.]+\.(jpg|png|gif|css|js))$ include/cache/optimizer.php?file=$1&type=$2&c=$0 [L,QSA,NC]
# Check if file *.* exist in the cache foldel
RewriteCond %{DOCUMENT_ROOT}/cache/$0 -f [NC]
RewriteRule ^(.+?)/?$ /cache/$0 [L]
# Check if file index.html exist in the cache foldel
RewriteCond %{DOCUMENT_ROOT}/cache/$0/index.html -f [NC]
RewriteRule ^(.+?)/?$ /cache/$0/index.html [L]
# Normal behave
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
【问题讨论】:
-
我的荣幸。如果文件存在于缓存文件夹中。它仍然重写到 php 文件
-
试试这个条件:
RewriteCond %{DOCUMENT_ROOT}/cache%{REQUEST_URI} !-f [NC] -
我已经更新了我的问题
-
这个 .htaccess 文件的位置是什么?还有其他文件吗?如果是,则发布完整的 .htaccess
-
htaccess 中的其他规则运行良好。这意味着 htaccess 被正确放置(在根文件夹中)。和图像和css文件分别位于。
标签: regex apache .htaccess mod-rewrite