Prestashop: 8 digits long image ID goes to 404

Created on 16 Jul 2019  路  5Comments  路  Source: PrestaShop/PrestaShop

Product images that have 8 digit long IDs return 404 instead of the image. The files are there, but when viewing the site, it returns 404 instead of the image.
The .htaccess rules support 8 digits, so it should work, and if I copy the resolved URL from a htaccess tester, that works, too. (or manually enter the img/p/1/2/3/4/5/6/7/8/12345678-large_default.jpg format)

To Reproduce
Method 1:

  1. Set ps_image database table's autoincrement value to be 8 digits
  2. Upload a product image
  3. Open this product in front office.

Method 2:

  1. Place an image to it's proper folder, for example: ./img/p/1/0/2/5/0/2/0/5/10250205-large_default.jpg
  2. Try to view this image, for the same example: http://example.com/img/p/1/0/2/5/0/2/0/5/10250205-large_default.jpg

Both methods will yield a 404 error instead of the image.
If you do this with only 7 digits, it still works. (example: 1025020 instead of 10250205)

Additional information
PrestaShop version: 1.7.5.1, 1.7.5.2
PHP version: 7.2.19, 7.3.6

Apache access_log shows a normal 404 response to the 8-digit URLs.
Sample:
1.3.3.7 - - [16/Jul/2019:21:56:31 +0200] "GET /10250205-large_default/zubehoer-9313.jpg HTTP/1.1" 404 6703 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36"

Image No change required

Most helpful comment

PHP and Prestashop version is completely irrelevant. (And my test shop works just fine on PHP 7.3, but focus on 7.2 then if you want.)
The limitation is from Apache, and probably affects all who reaches the 8 digit range since the $10 rewrite variable is broken.
"no change required" - at least whoever encounter this has my solution now.

All 5 comments

I found the reason behind this: Apache can't do more than 9 captures groups, so $10 is interpreted as $1 and a zero in this line:
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]
Source: https://stackoverflow.com/questions/5848962/rewriterule-using-10-11-12-and-so-on

I also found a solution. There might be a better ones, but this works for now.
Replace the line in my previous comment with these:

RewriteRule ^0([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/0/$1/$2/$3/$4/$5/$6/$7/0$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteRule ^1([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/$1/$2/$3/$4/$5/$6/$7/1$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteRule ^2([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/2/$1/$2/$3/$4/$5/$6/$7/2$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteRule ^3([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/3/$1/$2/$3/$4/$5/$6/$7/3$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteRule ^4([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/4/$1/$2/$3/$4/$5/$6/$7/4$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteRule ^5([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/5/$1/$2/$3/$4/$5/$6/$7/5$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteRule ^6([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/6/$1/$2/$3/$4/$5/$6/$7/6$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteRule ^7([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/7/$1/$2/$3/$4/$5/$6/$7/7$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteRule ^8([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/8/$1/$2/$3/$4/$5/$6/$7/8$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteRule ^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/9/$1/$2/$3/$4/$5/$6/$7/9$1$2$3$4$5$6$7$8$9.jpg [L]

Hi @DBBlueDeath,

Thanks for your report.
For your information: PrestaShop is not compatible with PHP 7.3, in fact, PrestaShop 1.7.0 to 1.7.3 is compatible with PHP 7.1 and PrestaShop 1.7.4 & 1.7.5 & PS1.7.6 are compatible with PHP 7.2.
For more details, you can follow this link: http://build.prestashop.com/news/prestashop-1-7-is-moving-to-symfony-3-4-and-php-5-6/
Next Major release PS1.7.7 will be compatible with PHP7.3.

Since your issue is fixed, I close the ticket, feel free to open a new one when needed.

Thanks!

PHP and Prestashop version is completely irrelevant. (And my test shop works just fine on PHP 7.3, but focus on 7.2 then if you want.)
The limitation is from Apache, and probably affects all who reaches the 8 digit range since the $10 rewrite variable is broken.
"no change required" - at least whoever encounter this has my solution now.

I have the same problem, i wish that this can be addressed with a proper solution, please reopen the issue and apply at least the solution provided by @DBBlueDeath ...

Was this page helpful?
0 / 5 - 0 ratings