简体   繁体   中英

Images url rewrite on magento site

I am facing issues of 404 errors with images on a Magento site, due to auto adding a trailing slash / on some images only. I am not able to shout out by coding.

So I am wanting to rewrite that url by .htaccess file but it's not working.

Wrong url: http://www.example.com/subdirectory/media/cpd/images/59480c2039d1e.png/

And to correct it I want it without the slash / :

http://www.example.com/subdirectory/media/cpd/images/59480c2039d1e.png

I am doing it as:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule ^.*/subdirectory/media/cpd/images/*.png/(.*)$ http://%{HTTP_HOST}/subdirectory/media/cpd/images/*.png$1 [L,R=301]
</IfModule>

Here I am using * star for all images names. please help me.

It's strange that you are having this problem. Perhaps you have a rule that is doing it. I would really look more at fixing that. But anyway, here is how to make your mod_rewrite work.

This is not glob matching, so you can's use star on its own like that, it refers to the previous character or group, so in this case you are saying "zero or more forward slashes / ".

This is how you can fix it:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^(.+\.png)/$ /$1 [L,R=301]
</IfModule>

There is no need to match anything but the .png followed by the forward slash, so this is simpler. Also the http:// and host will be added automatically for you.

Let me know any problems or if this isn't a good solution for you and I can update my answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM