Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.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 基于查询字符串的htaccess重定向规则_Php_.htaccess_Apache2 - Fatal编程技术网

Php 基于查询字符串的htaccess重定向规则

Php 基于查询字符串的htaccess重定向规则,php,.htaccess,apache2,Php,.htaccess,Apache2,我在/index.php文件上运行了动态调整大小服务,它将在/media/_缓存文件夹上创建经过处理(调整大小、优化)的文件,并附加查询参数值,如: ?w=200&h=200&cc=1 它将在以下位置创建一个文件: /媒体/_cache/content/2018/Apr/filename\u w200\u h200\u cc.jpg 在这里,我需要一个htaccess规则来验证文件是否已经存在,然后它应该直接从服务器发送到服务器,而不必转到/index.php页面 提前感谢。经过长时间的努力,我

我在/index.php文件上运行了动态调整大小服务,它将在/media/_缓存文件夹上创建经过处理(调整大小、优化)的文件,并附加查询参数值,如:

w=200&h=200&cc=1

它将在以下位置创建一个文件: /媒体/_cache/content/2018/Apr/filename\u w200\u h200\u cc.jpg

在这里,我需要一个htaccess规则来验证文件是否已经存在,然后它应该直接从服务器发送到服务器,而不必转到/index.php页面


提前感谢。

经过长时间的努力,我终于找到了这样做的方法:

#when url has width and height params only
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/media
RewriteCond %{QUERY_STRING} ^w=(\d+)&h=(\d+)$
RewriteRule ^(.*)\.(\w+)$ /media/_cache/$1_w%1_h%2.$2   [L]

#when url has width, height and cc
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/media
RewriteCond %{QUERY_STRING} ^w=(\d+)&h=(\d+)&cc=1$
RewriteRule ^(.*)\.(\w+)$ /media/_cache/$1_w%1_h%2_cc.$2    [L]

#if redirection rule not found file in cache, then it will be redirect to index.php for resizing & optimization
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule (.*) index.php/$1