Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 根据文件是否存在重写_Php_Apache_.htaccess_Mod Rewrite_Url Rewriting - Fatal编程技术网

Php 根据文件是否存在重写

Php 根据文件是否存在重写,php,apache,.htaccess,mod-rewrite,url-rewriting,Php,Apache,.htaccess,Mod Rewrite,Url Rewriting,我正在数据库驱动的网站上实现缓存。 我将缓存文件保存到/cache/as id.html 我有类似的URL 现在我需要检查这个12338.html文件是否存在于缓存中。如果它存在,则应该是server,否则应该重写为/viewArticle.php?id=12338 所以我需要的是: 1提取id号,如本例中的12338 2检查是否存在/cache/id.html,例如本例中的/cache/12338.html,并提供服务并退出 3Or serve/viewArticle.php?id=12338

我正在数据库驱动的网站上实现缓存。 我将缓存文件保存到/cache/as id.html

我有类似的URL

现在我需要检查这个12338.html文件是否存在于缓存中。如果它存在,则应该是server,否则应该重写为/viewArticle.php?id=12338

所以我需要的是:

1提取id号,如本例中的12338

2检查是否存在/cache/id.html,例如本例中的/cache/12338.html,并提供服务并退出

3Or serve/viewArticle.php?id=12338


我需要什么重写条件和规则?特别是用于从请求文件名提取id。

将此.htaccess文件放在服务器文档根目录中

<ifModule mod_rewrite.c>
  RewriteEngine on

  RewriteRule view/article/id/(.*).html$ /cache/$1.html [NC]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^cache(.*)\.html$ /viewArticle.php?id=$1  [NC]
</IfModule>

你看到了吗::是的,但是我如何检查id.html?链接中的答案有描述每一行的注释。有一行注释为检查文件是否存在于缓存中