search

Home  >  Q&A  >  body text

Title rewritten to: Image loading will be blocked when the image name contains hyphens, is too long, or relies on its position

I have some pictures placed in the C:\xampp\htdocs\catshop\assets\img folder under my website. If an image has a name like food-adult-wet-meo-sardine-in-prawn-jelly-400g, it will not show up on the website. However, if the name is like can1.png or can-1.png, it will display correctly (even though they are in the same position). If I name it food-prawnjelly.png, even with just one hyphen, it won't show up. foodprawnjelly.png doesn’t work either.

If I move the image to C:\xampp\htdocs\catshop\assets\img\food, it won't show up even though its name "worked" before, like can1.png.

I don't know if this is related or if it is causing the problem, but I am using rewrite rules to create beautiful links. A link like catshop/food/adult-cat.food will be rewritten to show-category.php, where appropriate filtering will be done to show the source from adult-cat -food products. I've used absolute links for the image paths (e.g. /catshop/assets/img/can-1.png)

Rewrite rules used: RewriteRule ^(\w )/(\w )$ show-category.php [NE,L]

If you need more information, please let me know, thank you!

catshop
├─ .htaccess
├─ assets
│  ├─ bootstrap
│  ├─ css
│  ├─ fonts
│  ├─ img
│  │  ├─ can-1.png
│  └─ js
├─ index.php
├─ login.php
├─ register.php
├─ show-category.php
└─ logout.php

Edit: Contents of .htaccess file

<IfModule mod_rewrite.c>

    Options +FollowSymLinks
    RewriteEngine On    # 打开重写引擎
    RewriteRule    home   index.php    [NC,L]    
    RewriteRule    food   show-category.php    [NC,L]    

    RewriteRule   ^((\w+)\/)+(\w.+)$  show-category.php    [NE,L]    

</IfModule>

P粉794851975P粉794851975307 days ago395

reply all(1)I'll reply

  • P粉604669414

    P粉6046694142024-01-17 09:49:34

    According to my understanding,

    1. You wish to parse images, etc. directly from /catshop/assets location
    2. Any .php file must be parsed
    3. Any other URL that does not contain the word "home" must resolve to /catshop/show-category.php

    (Please note: you may want to change the use of home as this will match any string containing the word home)

    <IfModule mod_rewrite.c>
    
        Options +FollowSymLinks
        RewriteEngine On    # 打开重写引擎
        RewriteRule    home   index.php    [NC,L]    
        RewriteRule   ^((?!assets)\w+\/)+(\w+\.\w+)(?<!\.php)$  catshop/show-category.php    [NE,L]    
    
    </IfModule>

    This will find any URL part that does not contain the words assets or .php

    reply
    0
  • Cancelreply