Jump to content

[SOLVED] Presta Shop: disable friendly url for images


Ramin007

Recommended Posts

after enabling "friendly urls" in prestashop management panel, all urls and image urls will change into something like this:

 

http://example.com/1545-large_default/1545.jpg

 

how can I disable friendly urls just for images? note that, I want to disable it just for images not all other urls!

 

I think it's done by changing some PHP codes, etc. I'm not a php programmer and I don't know what should I do!

Help me please.

 

Edited by Ramin007 (see edit history)
Link to comment
Share on other sites

Hi leo, thank you for answering.

 

- Which htaccess rules shoud be disabled? can you please give me the rules that should be disabled?

 

 

 

and to override the image link generation function from the image class.

 

- Where is "image class"? what should I do exactly? (Step by step)

 

Thanks.

Edited by Ramin007 (see edit history)
Link to comment
Share on other sites

Dear Leo, thank you again for your answer.

 

the image class is in the /classes folder, the good and best way is to override the function in the /override/classes folder.

 

Sorry, I'm newbie. Can you please tell me what shoud I do exactly? What files shoud I edit? What codes should I insert?

Please explain it in details.

 

----------------

 

1. I use PS v1.6.1.5

 

2. No I use an custom theme.

Edited by Ramin007 (see edit history)
Link to comment
Share on other sites

Thank you  El Patron for answering

 

For some reasons we have to disable url friendly for images. please just tell me the steps should be done.

 

Which rules should I remove from .htaccess file?

 

Which files should I edit in /override/classes directory? I'm not a PHP programmer please tell me what should I spouse to do?

 

Please explain it in details

 

Thanks

Edited by Ramin007 (see edit history)
Link to comment
Share on other sites

I  think you will need tot find a php programmer unless one of community is going to spend hours seeing  if they can make the code work.  Also 'for some reason', you explanation of requirement would be most helpful to community to know as there may be 'no reason' to do this and there we might be able to provide some insight.

  • Like 1
Link to comment
Share on other sites

Hi,

please be aware of the fact that this is a core modification, and the changes you are doing in the htaccess file will be reverted next time the htacccess will be regenerated by the prestashop ( please test this modifications on a development version before applying it to a live environment )

This modification usually should work with custom themes too, not only with the default theme.

For the product images these are the 3 steps to disable the rewrites and image link generation:

 

1: in .htaccess comment the lines that are referring to the .... img/p .... . this is the commented code from htaccess for domain.com : 

"

#RewriteCond %{HTTP_HOST} ^domain.com$
#RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
#RewriteCond %{HTTP_HOST} ^domain.com$
#RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.jpg [L]
#RewriteCond %{HTTP_HOST} ^domain.com$
#RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$1$2$3$4$5.jpg [L]
#RewriteCond %{HTTP_HOST} ^domain.com$
#RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg [L]
#RewriteCond %{HTTP_HOST} ^domain.com$
#RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg [L]
#RewriteCond %{HTTP_HOST} ^domain.com$
#RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg [L]
#RewriteCond %{HTTP_HOST} ^domain.com$
#RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg [L]
#RewriteCond %{HTTP_HOST} ^domain.com$
#RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg [L]
"
2: create Link.php file in the folder /override/clasess/ . this file should contain this code: 
"
<?php
class Link extends LinkCore
{
    public function getImageLink($name, $ids, $type = null)
    {
//         $not_default = false;
        $not_default = true;
 
        // Check if module is installed, enabled, customer is logged in and watermark logged option is on
        if (Configuration::get('WATERMARK_LOGGED') && (Module::isInstalled('watermark') && Module::isEnabled('watermark')) && isset(Context::getContext()->customer->id)) {
            $type .= '-'.Configuration::get('WATERMARK_HASH');
        }
 
        // legacy mode or default image
        $theme = ((Shop::isFeatureActive() && file_exists(_PS_PROD_IMG_DIR_.$ids.($type ? '-'.$type : '').'-'.(int)Context::getContext()->shop->id_theme.'.jpg')) ? '-'.Context::getContext()->shop->id_theme : '');
//         if ((Configuration::get('PS_LEGACY_IMAGES')
//             && (file_exists(_PS_PROD_IMG_DIR_.$ids.($type ? '-'.$type : '').$theme.'.jpg')))
//             || ($not_default = strpos($ids, 'default') !== false)) {
//             if ($this->allow == 1 && !$not_default) {
//                 $uri_path = __PS_BASE_URI__.$ids.($type ? '-'.$type : '').$theme.'/'.$name.'.jpg';
//             } else {
//                 $uri_path = _THEME_PROD_DIR_.$ids.($type ? '-'.$type : '').$theme.'.jpg';
//             }
//         } else {
            // if ids if of the form id_product-id_image, we want to extract the id_image part
            $split_ids = explode('-', $ids);
            $id_image = (isset($split_ids[1]) ? $split_ids[1] : $split_ids[0]);
            $theme = ((Shop::isFeatureActive() && file_exists(_PS_PROD_IMG_DIR_.Image::getImgFolderStatic($id_image).$id_image.($type ? '-'.$type : '').'-'.(int)Context::getContext()->shop->id_theme.'.jpg')) ? '-'.Context::getContext()->shop->id_theme : '');
//             if ($this->allow == 1) {
//                 $uri_path = __PS_BASE_URI__.$id_image.($type ? '-'.$type : '').$theme.'/'.$name.'.jpg';
//             } else {
                $uri_path = _THEME_PROD_DIR_.Image::getImgFolderStatic($id_image).$id_image.($type ? '-'.$type : '').$theme.'.jpg';
//             }
//         }
 
        return $this->protocol_content.Tools::getMediaServer($uri_path).$uri_path;
    }
}
"
 
3: delete or rename the file /cache/class_index.php so the override should be taken in consideration at the next pageload.

 

I am really curious about the fact that why you don't need rewrite for images?

Regards, Leo

  • Like 4
  • Thanks 1
Link to comment
Share on other sites

  • 6 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...