.htaccess and RewriteRule help needed asap

Discussion in 'Apache' started by xms, Mar 8, 2015.

  1. #1
    Hello,

    I'm using .htaccess to show existing images instead of images which does not exist.

    RewriteBase /images/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)_(.*)1200x900\.jpg$ esittely_$21200x900.jpg
    RewriteRule liiga1200x10.jpg esittely1200x10.jpg
    RewriteRule liiga670x10.jpg esittely670x10.jpg [L]

    Everyting works fine if an image does not exist.

    But if an image does exist, the second RewriteRule
    RewriteRule liiga1200x10.jpg esittely1200x10.jpg
    will be used.

    Why is that so? How could I modify my code to prevent that?
     
    Last edited: Mar 8, 2015
    xms, Mar 8, 2015 IP
  2. xms

    xms Active Member

    Messages:
    169
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #2
    Hello,

    I also have an another problem. I have this code:

    RewriteBase /images/
    RewriteCond %{REQUEST_URI} ^/(.*)/(.*)$
    RewriteRule liiga([0-9]{3,4})x10.jpg esittely$1x10.jpg [L]

    When I'm surfing on myexamplewebsite.com/kemii/liigasu.shtml, the RewriteCond is true. Everything is OK.

    When I'm surfing on myexamplewebsite.com/liigasu.shtml, the RewriteCond is true. Why is that so?
     
    xms, Mar 8, 2015 IP
  3. xms

    xms Active Member

    Messages:
    169
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Let's put this all that way:

    RewriteBase /images/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*)_(.*)1200x900.jpg esittely_$21200x900.jpg
    RewriteRule (.*)1200x10.jpg esittely1200x10.jpg
    RewriteRule (.*)670x10.jpg esittely670x10.jpg [L]

    When I arrive to myexamplewebsite.com/liigasu.shtml (no subdirectory), I would like to skip all the RewriteRules.

    When I arrive to subdirectory (for example: myexamplewebsite.com/kemii/liigasu.shtml), the RewriteRules should change these:

    (.*)_(.*)1200x900.jpg -> esittely_$21200x900.jpg
    (.*)1200x10.jpg -> esittely1200x10.jpg
    (.*)670x10.jpg -> esittely670x10.jpg
     
    Last edited: Mar 9, 2015
    xms, Mar 9, 2015 IP