New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug with friendly URLs and Media Servers #9203

Merged
merged 1 commit into from Jun 28, 2018

Conversation

Projects
None yet
7 participants
@lucasRolff
Contributor

lucasRolff commented Jun 20, 2018

Questions Answers
Branch? develop
Description? When "Friendly URLs" are enabled together with Media Servers, there's a race condition where it will result in 404 for images either on the Media Server URL or the actual shop URL.
The issue is caused by wrong rewrite rules and the lack of a rewrite rule matching the shop domain. The bug isn't directly apparent on Apache 2.4.x servers because Apache silently "fixes" the rules (RewriteCond ending with [OR] without a following RewriteCond). The fix is to include the shop domain.
Type? bug fix
Category? CO
BC breaks? No
Deprecations? No
Fixed ticket? http://forge.prestashop.com/browse/PSCSX-9983, http://forge.prestashop.com/browse/DOC-330
How to test? Setup a shop, with "Friendly URL" enabled under "SEO & URLs", then go to Advanced Parameters -> Performance and add a Media Server such as cdn.<domain.com>, ideally you' want this to actually be a CDN where the origin URL is configured to shop URL.
Expected result is that the image rewrite works on both the CDN/Media Server URL and shop URL at same time and the image is served as it should.

This change is Reviewable

@prestonBot

This comment has been minimized.

Collaborator

prestonBot commented Jun 20, 2018

Hello @lucasRolff!

This is your first pull request on the PrestaShop project. Thank you, and welcome to this Open Source community!

@mickaelandrieu mickaelandrieu requested a review from Quetzacoalt91 Jun 21, 2018

@maofree

This comment has been minimized.

maofree commented Jun 21, 2018

Hi

I could draw your attention to these bugs?

I think they are quite important as errors, but the months go by and nobody solves them
how can I increase the priority to solve them faster?

bye


at this moment for me the bigger problem on 1.7 is this seo issue
http://forge.prestashop.com/browse/BOOM-5448
http://forge.prestashop.com/browse/BOOM-4491

if a product has some combinations (now each combination has a own url, to avoid duplications it is used the canonical url) the canonical url of these pages does not exist, prestashop will redirect to the main combination (isas/3-5-prueb) but this has the canonical url (camisas/3-prueba) to the product page like in this example

https://www.mysite.com.ar/camisas/3-prueba-camisa.html (canonical url)
but this page doesn't exist and this page redirect to the default combination
https://www.mysite.com.ar/camisas/3-5-prueba-camisa.html

other seo errors are here
http://forge.prestashop.com/browse/NM-994
http://forge.prestashop.com/browse/NM-1005

this one for DNI
http://forge.prestashop.com/browse/BOOM-3848

problem when you update
http://forge.prestashop.com/browse/BOOM-3195

@prestonBot prestonBot added the develop label Jun 25, 2018

@mickaelandrieu

This comment has been minimized.

Contributor

mickaelandrieu commented Jun 25, 2018

I could draw your attention to these bugs?

how can I increase the priority to solve them faster?

You can provide patches using pull requests feature of GitHub, any help is welcome!

Thanks

@mickaelandrieu mickaelandrieu changed the title from CO: Fix bug with friendly URLs and Media Servers to Fixed bug with friendly URLs and Media Servers Jun 25, 2018

@prasanthSelvar prasanthSelvar self-assigned this Jun 25, 2018

@prasanthSelvar prasanthSelvar removed their assignment Jun 25, 2018

@prasanthSelvar

This comment has been minimized.

prasanthSelvar commented Jun 25, 2018

Hello @lucasRolff,

Thanks for your PR.
But your fix finally concerns the project 1.6 or 1.7?
Because I didn't manage to reproduce your issue on 1.7.3.3.

@lucasRolff

This comment has been minimized.

Contributor

lucasRolff commented Jun 25, 2018

@prasanthSelvar https://github.com/PrestaShop/PrestaShop/blob/1.7.3.x/classes/Tools.php - the code is exactly the same - so it affects every Prestashop version containing the same code.

Apache "handles" it (thus you won't experience a bug), since it kinda ignores RewriteCond lines with [OR] in the end if there's no RewriteCond following it.

Litespeed for example, the problem is reproducible because it actually does the RewriteCond as it's supposed to be handled.

In my comment over at the forge.prestashop, I also explain why it's not working as intended with a test case: http://forge.prestashop.com/browse/PSCSX-9983?focusedCommentId=170029&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-170029

I can set up a Prestashop 1.7.3.x test installation on a Litespeed server if you'd like, so you can see the broken behaviour.

@lucasRolff

This comment has been minimized.

Contributor

lucasRolff commented Jun 25, 2018

@prasanthSelvar - small update - regarding Prestashop 1.7.3.x it's a bit harder to test actually since it requires an additional step - after you've enabled a media URL, then go back to SEO settings and click "Save" again in the section where the Friendly URL selection is set.

Updating the Media Servers alone in Prestashop 1.7, doesn't call the generateHtaccess function within Tools.php as far as I can see - thus the bug won't occur, but resaving the friendly URL setting, will call generateHtaccess, and thus producing the same kind of code that Prestashop 1.6.x does.

I'm sorry I didn't catch this in the reproduction steps I did, so to reproduce in 1.7:

  • Advanced Parameters -> Performance -> Enable a Media Server
  • Go to "Shop Parameters" -> "Traffic & SEO", make sure "Friendly URL" is set to "Yes" and click "Save".

This will render the .htaccess file with following content:

# Images
RewriteCond %{HTTP_HOST} ^cdn-static.mediaservers.prestashop-domain.com$ [OR]
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
RewriteCond %{HTTP_HOST} ^cdn-static.mediaservers.prestashop-domain.com$ [OR]
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} ^cdn-static.mediaservers.prestashop-domain.com$ [OR]
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} ^cdn-static.mediaservers.prestashop-domain.com$ [OR]
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} ^cdn-static.mediaservers.prestashop-domain.com$ [OR]
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} ^cdn-static.mediaservers.prestashop-domain.com$ [OR]
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} ^cdn-static.mediaservers.prestashop-domain.com$ [OR]
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} ^cdn-static.mediaservers.prestashop-domain.com$ [OR]
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]
RewriteCond %{HTTP_HOST} ^cdn-static.mediaservers.prestashop-domain.com$ [OR]
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L]
RewriteCond %{HTTP_HOST} ^cdn-static.mediaservers.prestashop-domain.com$ [OR]
RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]
# AlphaImageLoader for IE and fancybox
RewriteRule ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 [L]

As you see, once again we end up with the RewriteCond ^domain.com$ [OR] without a proceeding RewriteCond - the result will be a mismatch in the rewrite rules if we try to access the one of the product images via the shop's own URL as such:

curl -I https://my-prestashop17-domain.com/2-home_default/hummingbird-printed-t-shirt.jpg
HTTP/2 404
p3p: CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"
powered-by: PrestaShop
set-cookie: PHPSESSID=a8b0d2c058d4f3c4e1a605e41410de43; path=/
expires: Thu, 19 Nov 1981 08:52:00 GMT
cache-control: no-store, no-cache, must-revalidate
pragma: no-cache
content-type: text/html; charset=utf-8
date: Mon, 25 Jun 2018 17:21:33 GMT
accept-ranges: bytes
server: LiteSpeed
alt-svc: quic=":443"; ma=2592000; v="35,37,38,39"

The rewrite debugging:

2018-06-25 19:25:35.147345 [INFO] [80.61.160.xxx:56313:HTTP2-1] [REWRITE] strip base: '/' from URI: '/2-home_default/hummingbird-printed-t-shirt.jpg'
2018-06-25 19:25:35.147347 [INFO] [80.61.160.xxx:56313:HTTP2-1] [REWRITE] Rule: Match '2-home_default/hummingbird-printed-t-shirt.jpg' with pattern '.', result: 1
2018-06-25 19:25:35.147349 [INFO] [80.61.160.xxx:56313:HTTP2-1] [REWRITE] set ENV: 'REWRITEBASE:/'
2018-06-25 19:25:35.147350 [INFO] [80.61.160.xxx:56313:HTTP2-1] [REWRITE] No substition
2018-06-25 19:25:35.147352 [INFO] [80.61.160.xxx:56313:HTTP2-1] [REWRITE] Rule: Match '2-home_default/hummingbird-printed-t-shirt.jpg' with pattern '^api$', result: -1
2018-06-25 19:25:35.147353 [INFO] [80.61.160.xxx:56313:HTTP2-1] [REWRITE] Rule: Match '2-home_default/hummingbird-printed-t-shirt.jpg' with pattern '^api/(.*)$', result: -1
2018-06-25 19:25:35.147357 [INFO] [80.61.160.xxx:56313:HTTP2-1] [REWRITE] Rule: Match '2-home_default/hummingbird-printed-t-shirt.jpg' with pattern '^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$', result: 3
2018-06-25 19:25:35.147358 [INFO] [80.61.160.xxx:56313:HTTP2-1] [REWRITE] Cond: Match 'my-prestashop17-domain.com' with pattern '^cdn-static.mediaservers.prestashop-domain.com$', result: -1
2018-06-25 19:25:35.147360 [INFO] [80.61.160.xxx:56313:HTTP2-1] [REWRITE] Rule: Match '2-home_default/hummingbird-printed-t-shirt.jpg' with pattern '^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$', result: -1
2018-06-25 19:25:35.147362 [INFO] [80.61.160.xxx:56313:HTTP2-1] [REWRITE] Rule: Match '2-home_default/hummingbird-printed-t-shirt.jpg' with pattern '^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$', result: -1
2018-06-25 19:25:35.147364 [INFO] [80.61.160.xxx:56313:HTTP2-1] [REWRITE] Rule: Match '2-home_default/hummingbird-printed-t-shirt.jpg' with pattern '^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$', result: -1
2018-06-25 19:25:35.147366 [INFO] [80.61.160.xxx:56313:HTTP2-1] [REWRITE] Rule: Match '2-home_default/hummingbird-printed-t-shirt.jpg' with pattern '^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$', result: -1
2018-06-25 19:25:35.147367 [INFO] [80.61.160.xxx:56313:HTTP2-1] [REWRITE] Rule: Match '2-home_default/hummingbird-printed-t-shirt.jpg' with pattern '^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$', result: -1
2018-06-25 19:25:35.147369 [INFO] [80.61.160.xxx:56313:HTTP2-1] [REWRITE] Rule: Match '2-home_default/hummingbird-printed-t-shirt.jpg' with pattern '^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$', result: -1
2018-06-25 19:25:35.147371 [INFO] [80.61.160.xxx:56313:HTTP2-1] [REWRITE] Rule: Match '2-home_default/hummingbird-printed-t-shirt.jpg' with pattern '^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$', result: -1
2018-06-25 19:25:35.147373 [INFO] [80.61.160.xxx:56313:HTTP2-1] [REWRITE] Rule: Match '2-home_default/hummingbird-printed-t-shirt.jpg' with pattern '^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$', result: -1
2018-06-25 19:25:35.147374 [INFO] [80.61.160.xxx:56313:HTTP2-1] [REWRITE] Rule: Match '2-home_default/hummingbird-printed-t-shirt.jpg' with pattern '^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$', result: -1
2018-06-25 19:25:35.147376 [INFO] [80.61.160.xxx:56313:HTTP2-1] [REWRITE] Rule: Match '2-home_default/hummingbird-printed-t-shirt.jpg' with pattern '^images_ie/?([^/]+)\.(jpe?g|png|gif)$', result: -1
2018-06-25 19:25:35.147377 [INFO] [80.61.160.xxx:56313:HTTP2-1] [REWRITE] Rule: Match '2-home_default/hummingbird-printed-t-shirt.jpg' with pattern '^.*$', result: 1

On 7th line in the above block, we see that there's a match with the pattern ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ - (result: 3)

However, because of the RewriteCond RewriteCond %{HTTP_HOST} ^cdn-static.mediaservers.prestashop-domain.com$ [OR] the result of the condition is -1 - meaning it's not matching - since the condition isn't matching it will simply proceed trying to match the remaining rewrite rules, all which fails but the last one being ^.*$.

This will result in a 404 for the image.

The fix I do in the PR will basically just ensure we always have the shop URL in the rewriteCond as well, because it will result in a match of the condition (and return 1), and the rewrite rules will succeed as expected.

@prasanthSelvar

This comment has been minimized.

prasanthSelvar commented Jun 27, 2018

Hi @lucasRolff,

Thank you for the explanation but to be really clear in that issue I am very interested in your test solution that you have proposed.

Thanks again!

@lucasRolff

This comment has been minimized.

Contributor

lucasRolff commented Jun 27, 2018

@prasanthSelvar

Working:

URL: https://presta17.elamedia.org/

This is a working Prestashop 1.7.x installation, it has a "Media Server" configured with URL 8d1e2be4b2b7bc5dc3016f5dd1c6a988b373f8f7.hosting4cdn.com - the URL runs on a CDN that is set to fetch images from presta17.elamedia.org.

I've patched the above Prestashop 1.7.x installation with my pull request, as you can see images such as the Media URL and shop URL works:

Media URL: https://8d1e2be4b2b7bc5dc3016f5dd1c6a988b373f8f7.hosting4cdn.com/2-home_default/hummingbird-printed-t-shirt.jpg

Shop URL: https://presta17.elamedia.org/2-home_default/hummingbird-printed-t-shirt.jpg

Direct URL: https://presta17.elamedia.org/img/p/2/2-home_default.jpg

htaccess:

# Images
RewriteCond %{HTTP_HOST} ^8d1e2be4b2b7bc5dc3016f5dd1c6a988b373f8f7.hosting4cdn.com$ [OR]
RewriteCond %{HTTP_HOST} ^presta17.elamedia.org$
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
RewriteCond %{HTTP_HOST} ^8d1e2be4b2b7bc5dc3016f5dd1c6a988b373f8f7.hosting4cdn.com$ [OR]
RewriteCond %{HTTP_HOST} ^presta17.elamedia.org$
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} ^8d1e2be4b2b7bc5dc3016f5dd1c6a988b373f8f7.hosting4cdn.com$ [OR]
RewriteCond %{HTTP_HOST} ^presta17.elamedia.org$
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} ^8d1e2be4b2b7bc5dc3016f5dd1c6a988b373f8f7.hosting4cdn.com$ [OR]
RewriteCond %{HTTP_HOST} ^presta17.elamedia.org$
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} ^8d1e2be4b2b7bc5dc3016f5dd1c6a988b373f8f7.hosting4cdn.com$ [OR]
RewriteCond %{HTTP_HOST} ^presta17.elamedia.org$
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} ^8d1e2be4b2b7bc5dc3016f5dd1c6a988b373f8f7.hosting4cdn.com$ [OR]
RewriteCond %{HTTP_HOST} ^presta17.elamedia.org$
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} ^8d1e2be4b2b7bc5dc3016f5dd1c6a988b373f8f7.hosting4cdn.com$ [OR]
RewriteCond %{HTTP_HOST} ^presta17.elamedia.org$
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} ^8d1e2be4b2b7bc5dc3016f5dd1c6a988b373f8f7.hosting4cdn.com$ [OR]
RewriteCond %{HTTP_HOST} ^presta17.elamedia.org$
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]
RewriteCond %{HTTP_HOST} ^8d1e2be4b2b7bc5dc3016f5dd1c6a988b373f8f7.hosting4cdn.com$ [OR]
RewriteCond %{HTTP_HOST} ^presta17.elamedia.org$
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L]
RewriteCond %{HTTP_HOST} ^8d1e2be4b2b7bc5dc3016f5dd1c6a988b373f8f7.hosting4cdn.com$ [OR]
RewriteCond %{HTTP_HOST} ^presta17.elamedia.org$
RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]
# AlphaImageLoader for IE and fancybox
RewriteRule ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 [L]

Broken:

URL: https://broken.presta17.elamedia.org/

This Prestashop 1.7.x installation, has a "Media Server" configured with the URL b5baae24aaa9466534e85638d47d516b7cc0836f.hosting4cdn.com - the URL runs on a CDN that is set to fetch images from broken.presta17.elamedia.org.

Basically same setup as the first shop.

In this case I've not patched the code to include my fix.

As you can see on the front-page, the product images doesn't work.

https://b5baae24aaa9466534e85638d47d516b7cc0836f.hosting4cdn.com/2-home_default/hummingbird-printed-t-shirt.jpg

The CDN URL will give a 404 not found page.

https://broken.presta17.elamedia.org/2-home_default/hummingbird-printed-t-shirt.jpg

The shop URL will also give a 404 not found page.

This happens because of the missing RewriteCond %{HTTP_HOST} ^broken.presta17.elamedia.org$

If we access the raw URL to the image, you can see it exists on the shop: http://broken.presta17.elamedia.org/img/p/2/2-home_default.jpg

(2-home_default/hummingbird-printed-t-shirt.jpg will turn into img/p/2/2-home_default.jpg).

htaccess:

# Images
RewriteCond %{HTTP_HOST} ^b5baae24aaa9466534e85638d47d516b7cc0836f.hosting4cdn.com$ [OR]
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
RewriteCond %{HTTP_HOST} ^b5baae24aaa9466534e85638d47d516b7cc0836f.hosting4cdn.com$ [OR]
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} ^b5baae24aaa9466534e85638d47d516b7cc0836f.hosting4cdn.com$ [OR]
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} ^b5baae24aaa9466534e85638d47d516b7cc0836f.hosting4cdn.com$ [OR]
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} ^b5baae24aaa9466534e85638d47d516b7cc0836f.hosting4cdn.com$ [OR]
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} ^b5baae24aaa9466534e85638d47d516b7cc0836f.hosting4cdn.com$ [OR]
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} ^b5baae24aaa9466534e85638d47d516b7cc0836f.hosting4cdn.com$ [OR]
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} ^b5baae24aaa9466534e85638d47d516b7cc0836f.hosting4cdn.com$ [OR]
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]
RewriteCond %{HTTP_HOST} ^b5baae24aaa9466534e85638d47d516b7cc0836f.hosting4cdn.com$ [OR]
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L]
RewriteCond %{HTTP_HOST} ^b5baae24aaa9466534e85638d47d516b7cc0836f.hosting4cdn.com$ [OR]
RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]
# AlphaImageLoader for IE and fancybox
RewriteRule ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 [L]

Conclusion

The only difference between the two shops (other than domain names) is the fact that one contains my fix in this PR (presta17.elamedia.org) and one does not (broken.presta17.elamedia.org)

The fix ensures images are accessible on the shop + media servers - and that's ideally what Prestashop wants.

My end goal, is the fact Prestashop (1.6 and 1.7) does proper rewrites and not rely on a buggy condition handling in Apache - as a result we'll also end up with working sites.

Update:
The two sites are by the way hosted on the same Litespeed server.

@prasanthSelvar

This comment has been minimized.

prasanthSelvar commented Jun 28, 2018

Thanks a lot @lucasRolff!

@prasanthSelvar prasanthSelvar removed their assignment Jun 28, 2018

@PierreRambaud PierreRambaud merged commit 9d5341a into PrestaShop:develop Jun 28, 2018

2 checks passed

Codacy/PR Quality Review Up to standards. A positive pull request.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@PierreRambaud

This comment has been minimized.

Contributor

PierreRambaud commented Jun 28, 2018

Thanks a lot @lucasRolff for your feedback and explanation!

@lucasRolff

This comment has been minimized.

Contributor

lucasRolff commented Jun 28, 2018

@prasanthSelvar thanks! quick Q - by being merged into develop branch, does that mean it will go as bugfix releases for both 1.6 and 1.7? (which is the idea)

Thanks!

@PierreRambaud

This comment has been minimized.

Contributor

PierreRambaud commented Jun 29, 2018

Hi @lucasRolff Merging to develop will only target the next release (in this situation 1.7.5), if you need this fix, you can target 1.6.1.x, and 1.7.4.x, (using cherry-pick will maybe work) we will be happy to test and merge it again :)
Thanks again

@lucasRolff

This comment has been minimized.

Contributor

lucasRolff commented Jun 29, 2018

@prasanthSelvar I put the target branch as 1.6.x, 1.7.x and develop - since I want it to go into all releases.

The testing was done on 1.6.x and 1.7.4.x - so, in fact, it's already tested, and was targeted to the specific versions.

I even replied to the comment you made ( #9203 (comment) ) - that it's concerning all Prestashop versions, and since it's a bug - I'd like it to get fixed in all Prestashop versions.

I don't want a (serious) bug that makes Prestashop unusable to only target a new version - that's just silly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment