Htaccess Problem


I’ve got one major problem in Yii htaccess configuration.

I want to redirect a request from




My htaccess looks like that

Options +FollowSymLinks

RewriteEngine on

RewriteBase /

# Add additional file extensions to the list as needed.

RewriteCond %{REQUEST_FILENAME} ([a-z_]*?)_picture/(.*?)\.(?:jpg|png|jpeg)$

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([a-z_]*)_picture/(.*)/(.*)\.(jpg|png|jpeg)$ thumbnailer/create?type=$1&size=$2&pictureFilename=$3&extension=$4 [QSA]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ index.php/$1 [QSA,L]

but there is something wrong couse redirect works when there are no last two lines, but when I redirect it to index I’ve got 404 error. Could anyone help me with create working htaccess rule?

You could use Yii URL routing for this instead of working with .htaccess

'<type:\w+>_picture/<size:\d+x\d+>/<pictureFilename:.+?>.<extension:\w+>' => 'thumbnailer/create'

This will call the thumbnailer controller and its create action by giving all the named parameters defined in the route definition.

See also the guide on this topic:

OMG xD why I didn’t think about that :) thanks a lot! now everythink works fine.

I’ve got one more question, how that redirect works? It will work with every request or if file already exist under that url it will shown the image?

if you have the following lines in you .htaccess it will only call yii if file does not exist.

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d