Issue
If I type this: "http://examplepage.com/gallery/examplecagegory/1-test-picture.jpg" to the browser.
Go to webroot: "app/webroot/gallery/pictures/1.jpg"
I tried:
Router::connect('/gallery/:slug_category/:id-:slug.:extension',
array('webroot/gallery/pictures'),
array(
'pass' => array('id', 'slug'),
'id' => '[0-9]+'
)
);
But I stucked in the second row... :-/
Solution
This is not something you can do with routing, as the book states:
Routing is a feature that maps URLs to controller actions.
An image resource is not a controller action. You should just use a plain RewriteRule in the .htaccess file in app/webroot
to rewrite all calls. Something like this should do the trick:
RewriteRule ^gallery/[a-z]+/([0-9]+)-[a-z-]+\.([a-z]{3})$ /gallery/pictures/$1.$2
Please do be aware that the HtmlHelper searches for images in the app/webroot/images
folder by default, so you will need to use absolute URLs (prefix all image calls with a leading slash) to use your rewritten path, for example this will not work:
$this->Html->image('gallery/examplecategory/1-test-picture.jpg');
You should use this instead:
$this->Html->image('/gallery/examplecategory/1-test-picture.jpg');
Answered By - Oldskool Answer Checked By - Katrina (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.