本文介绍了如果缓存文件夹中不存在文件,则htaccess重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查缓存文件夹中是否不存在文件,然后将其重新连接到php文件.
I want to check if file is not exist in the cache folder, than rewire it to a php file.
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/images/logo.jpg,可从example/cache/images/logo.jpg检查 eg2:example/images/user/user1.jpg从example/cache/user/user1.jpg进行检查 eg3:example/css/style.css来检查example/cache/css/style.css
eg1 : example/images/logo.jpg to check from example/cache/images/logo.jpg eg2 : example/images/user/user1.jpg to check from example/cache/user/user1.jpg eg3 : example/css/style.css to check from example/cache/css/style.css
请帮助我.
谢谢.
我的htaccess代码:
My htaccess code:
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]推荐答案
您需要删除否定检查!并将其设为肯定:
You need to remove negative check ! and make it positive:
RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] # Admin area RewriteRule ^admin(.*) admin$1 [L] # Check if file index.html exist in the cache foldel RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{DOCUMENT_ROOT}/cache/$1/index.html -f [NC] RewriteRule ^(.+?)/?$ /cache/$1/index.html [L] # Check if file *.* exist in the cache foldel RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{DOCUMENT_ROOT}/cache/$1 -f [NC] RewriteRule ^(.+?)/?$ /cache/$1 [L] RewriteRule ^([^.]+\.(jpg|png|gif|css|js))$ include/cache/optimizer.php?file=$1&type=$2&c=$0 [L,QSA,NC] # Normal behave RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php [L]更多推荐
如果缓存文件夹中不存在文件,则htaccess重写
发布评论