Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.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
Regex 当文件存在但在目录中时,如何重定向到该文件?_Regex_Apache_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Regex 当文件存在但在目录中时,如何重定向到该文件?

Regex 当文件存在但在目录中时,如何重定向到该文件?,regex,apache,.htaccess,mod-rewrite,redirect,Regex,Apache,.htaccess,Mod Rewrite,Redirect,如何重定向WebBrowser请求: http://example.com/ico/my_ico.png 到 当图标存在于_缓存目录中时,并重定向到: http://example.com/ico/index.php?page=my_ico.png 当_缓存目录中不存在请求的文件时 我尝试了这个方法,但它一直指向index.php,而从未指向_cachedir: Options +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_F

如何重定向WebBrowser请求:

http://example.com/ico/my_ico.png

当图标存在于_缓存目录中时,并重定向到:

http://example.com/ico/index.php?page=my_ico.png
当_缓存目录中不存在请求的文件时

我尝试了这个方法,但它一直指向index.php,而从未指向_cachedir:

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !index.php
RewriteRule ^(.*)$ _cache/$1 [QSA,L]
RewriteRule ^(.*)$ index.php?page=$1 [QSA,L]

您可以在
/ico/.htaccess
文件中使用此代码:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /ico/

RewriteCond %{DOCUMENT_ROOT}/ico/_cache/$1 -f [NC]
RewriteRule ^(.+)$ _cache/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?page=$1 [L]
Options +FollowSymlinks
RewriteEngine On
RewriteBase /ico/

RewriteCond %{DOCUMENT_ROOT}/ico/_cache/$1 -f [NC]
RewriteRule ^(.+)$ _cache/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?page=$1 [L]