The server resizes images in the background, so a trace is made to control the cache. crutch from redirects: .htaccess

RedirectMatch "^/images/uploaded/([0-9]+)/([^\.]+)\.(png|jpg|gif)$" /image_view.php?user_id=$1\&file=$2.$3 

 <?php if (isset($_GET['file']) && isset($_GET['user_id'])) { $path_to_image = 'images/uploaded/' . intval($_GET['user_id']) . '/' . $_GET['file']; $modified = filemtime($path_to_image); header('Location:' . $path_to_image . '?' . $modified, true, 303); } 

As it is not difficult to guess, there is a looping, because php generates redirection along the same path, with the addition of the $ modified parameter, how to exclude this redirection from htaccess and take into account calls to (png | jpg | gif) without the "?"

    1 answer 1

    It may be worth replacing RedirectMatch with RewriteCond and RewriteRule

     RewriteEngine On RewriteCond %{QUERY_STRING} ^$ RewriteCond %{REQUEST_URI} ^\/images\/uploaded\/(\d+)/([^\.]+)\.(png|jpg|gif)$ RewriteRule .* http://your.site/image_view.php?user_id=%1&file=%2.%3 [L] 
    • strange, did not work the redict - aliokero
    • @aliokero, checked on localhost with Apache / 2.4.10 (Win32). Forwarding works by adding the timestamp to the parameters, there is no looping. - Visman
    • checked on localhost and production, still no redirect occurs (what could be the reason? - aliokero
    • @aliokero, mod_rewrite you have enabled? - Visman
    • if the directory on the server exists images, then redirection does not occur if you change to RewriteCond% {REQUEST_URI} ^ \ / images3 \ / uploaded \ / (\ d +) / ([^ \.] +) \. (png | jpg | gif ) $ - images3, then there is a redirect, there are not enough flags? - aliokero