Learn about Centmin Mod LEMP Stack today
Register Now

Nginx Exclude certain folder from 404 redirect for pictures

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by Tythus, Aug 5, 2015.

  1. Tythus

    Tythus Premium Member Premium Member

    56
    9
    8
    Aug 6, 2014
    Ratings:
    +12
    Local Time:
    5:16 PM
    Code:
    location ~* \.(png|jpg|jpeg|gif) {
        try_files $uri $uri/ @noimage;
    }
    location @noimage {
        rewrite ^ /404.gif;
    }
    
    I have been using this to redirect to a 404 image under an image not being found but would anyone know how to exclude a certain tree from this such as website.com/lel/
     
  2. eva2000

    eva2000 Administrator Staff Member

    28,957
    6,573
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,755
    Local Time:
    2:16 AM
    Nginx 1.13.x
    MariaDB 5.5
    should be able to just define the excluded location specifically
    Code:
    location ~* /exclude {
    
    }
    
     
  3. Tythus

    Tythus Premium Member Premium Member

    56
    9
    8
    Aug 6, 2014
    Ratings:
    +12
    Local Time:
    5:16 PM
    so

    Code:
    location ~* /lel{
    
    }
    Should work? will that work for subfolders or only this folder?
     
  4. eva2000

    eva2000 Administrator Staff Member

    28,957
    6,573
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,755
    Local Time:
    2:16 AM
    Nginx 1.13.x
    MariaDB 5.5
    it matches all urls with /lel so yes subfolders it should