htaccess->显示文件(如果在缓存目录中),如果不继续 [英] htaccess->show file if in cache directory, if not continue

查看:75
本文介绍了htaccess->显示文件(如果在缓存目录中),如果不继续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用缓存玩游戏。我想要的是以下逻辑:

Im playing arround with cache. What I want is the following logic:

if ( file_exist(/cache/$request_uri.txt) ){ 
    1. show that file
    2. Stop all rewrite actions, but perform other actions (like charset, error_pages)
}
else{
    do whatever you normally do
}

小例子。我有以下文件

http://domain.com/example-123.htm (请求的页面)

http:// domain .com / cache / example-123.htm.txt (该页面的缓存版本)

Small example. I have the following files
http://domain.com/example-123.htm (the requested page)
http://domain.com/cache/example-123.htm.txt (the cache-version of that page)

http://domain.com/someDir/example-456.htm (请求的页面)

http://domain.com/cache/someDir/example-456.htm.txt (该页面的缓存版本)

http://domain.com/someDir/example-456.htm (the requested page)
http://domain.com/cache/someDir/example-456.htm.txt (the cache-version of that page)

我不想显示index.php来解析url并构建页面,而是想显示该文件并停止

Instead of getting the index.php to parse the url and build the page, I want to show that file and stop.

我虽然可以这样做,但事实并非如此:

I though this would do it, but it doesn't:

RewriteCond ^cache%{REQUEST_URI}\.txt -f # check if the file exists in cache dir
RewriteRule ^(.*) /cache/$1\.txt [L] # i so, rewrite rule to it and stop

[L] 根据我的备忘单,最后-停止处理规则。如果那仅意味着重写规则,那不是我所需要的。

我无法使其正常工作,我可以按正确的方向进行推动:)

The [L] does, according to my cheatsheet, "Last - stop processing rules". If that only means the rewrite rules, than thats what I need.
I cant get it to work, I could use a push in the right direction :)

我已将答案标记为解决方案,确实说明了应做的事情。我希望在.htaccess文件中使用此文件的原因是因为这样既不会调用我的index.php,也不会数据库。一种非常快速简便的方法。

但是,这带来了一个新问题:某些项目(例如菜单)可以更改(通常)。那意味着我必须每次更改都删除所有缓存文件,这将使其无法有效工作。

要解决此问题,我将查看我是否可以使用一些巧妙的.shtml文件来解决此问题。问题(可能需要允许php在shtml文件中使用)。

只要对那些感兴趣的人有了不错的工作,我会尽快更新此帖子

I've marked an answer as solution it, did exaclty what it should. The reason I want this in the .htaccess file is because this way my index.php doesn't get called, nor does the database. A very fast and light method.
However, this creates a new problem: Some items (like the menu) can change (often). That would mean I'd have to delete all cache files every change, which prohibits it from working efficient.
To tackle this problem, im going to see if I can use some clever .shtml files to fix that problem (might need to allow php to woth in shtml files).
I'll update this post as soon as I've got something nice working for those interested

推荐答案

您可以尝试以下规则:

# check if the file exists in cache dir
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}cache/$1.txt -f
RewriteRule ^(.+?)/?$ /cache/$1.txt [L]

这篇关于htaccess->显示文件(如果在缓存目录中),如果不继续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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