如果缓存文件夹中不存在文件,则htaccess重写 [英] htaccess rewrite if file not exists in cache folder

查看:67
本文介绍了如果缓存文件夹中不存在文件,则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.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

eg1 : example.com/images/logo.jpg to check from example.com/cache/images/logo.jpg
eg2 : example.com/images/user/user1.jpg to check from example.com/cache/user/user1.jpg
eg3 : example.com/css/style.css to check from example.com/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重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆