<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} .*wp-content/uploads/.(jpg|jpeg|png|gif)$ [NC] !-f
#вариант который должен работать, но нет
#RewriteRule ^/wp-content/uploads/(....)/(..)/(..)(.*)$ "testp/$3/$3$4" [L]
#еще 1
#RewriteRule ^/wp-content/uploads/(....)/(..)/(..)(.*)$ "/testp/$3/$3$4" [L]
#и еще
#RewriteRule ^/wp-content/uploads/2019/01/(..)(.+)$ "/testp/$1/$1$2" [L]
#вариант "и даже так нет?"
RewriteRule ^/wp-content/uploads/2019/01/01512b3c874f00c1266e66b54a51bc20.jpg$ "/testp/01/01512b3c874f00c1266e66b54a51bc20.jpg" [L]
</IfModule>
#IMG Mapping by symlink#
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
#RewriteCond %{REQUEST_URI} ^/wp-content/uploads/(\d{4})/(\d{2})/(..)(.*)\.(jpg|jpeg|png|gif)$ [NC]
#RewriteRule (.*) /testp/$3/$3$4.$5
#RewriteCond %{REQUEST_URI} .*wp-content/uploads/(....)/(..)/.(jpg|jpeg|png|gif)$ [NC] !-f
RewriteCond %{REQUEST_URI} .*wp-content/uploads/.(jpg|jpeg|png|gif)$ [NC] !-f
# 1 2 3 4
RewriteRule ^/wp-content/uploads/(....)/(..)/(..)(.*)$ "/testp/$3/$3$4"
#RewriteRule ^/wp-content/uploads/(....)/(..)/(..)(.*)$ "testp/$3/$3$4"
</IfModule>
#/#
root@159:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 32G 0 32G 0% /dev
tmpfs 6.3G 2.1M 6.3G 1% /run
/dev/sda3 437G 346G 69G 84% /
tmpfs 32G 30M 32G 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/sda2 488M 80M 384M 18% /boot
tmpfs 6.3G 20K 6.3G 1% /run/user/0
/dev/sdb 469G 295G 151G 67% /mnt/ssd
tmpfs 6.3G 16K 6.3G 1% /run/user/125
/dev/sdc 3.6T 3.3T 186G 95% /mnt/hdd
tmpfs 6.3G 0 6.3G 0% /run/user/1000
function img_get_mime_type($file)
{
$mime_types = array("gif" => "image/gif", "png" => "image/png", "jpeg" => "image/jpg", "jpg" => "image/jpg",);
$file_exp = explode('.', $file);
$extension = strtolower(end($file_exp));
if (array_key_exists($extension, $mime_types)) {
return $mime_types[$extension];
}
return "application/force-download";
}
$mime = img_get_mime_type($image);
header('Content-type: ' . $mime);
fpassthru(fopen($image, 'rb'));
RewriteRule (.*) "/testp/$3/$3$4.$5" [L]