Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to rewrite all nonexisting file.jpg|.png|.gif to directory /pics/file.jpg|...?

    Hi!
    In my .htaccess file I want to achieve the following.

    1. If the picture file exists (e.g. dir1/pic.jpg or png or gif), it should be delivered without any rewrite.
    2. If it does not exists (e.g. dir2/pic2.jpg or png or gif), it should be rewritten to /pics/pic2.jpg or png or gif.
    3. If the file then doesn'T even exists in /pictures, rewrite shouldn't do anything more but just indicate as usual to the browser, that the file doesn't exists.

    4. If the file doesn't end with .jpg .png or .gif at all, then the next rewrite-rule (for all other file types) should be followed.

    Right now I tried for example all the outcommented things, but got always an 500 error:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    #RewriteRule ^/(.*\.(png|gif|jpg)) /pics/$1 [L,NS,NC]
    #RewriteRule ^/(.*\.(png|gif|jpg|jpeg)) /pics%{REQUEST_URI} [L,NS,NC]
    #RewriteRule ^/(.*\.(png|gif|jpg)) /pics/$1 [NC]
    #RewriteRule ^/(.*\.(png|gif|jpg|jpeg)) /pics%{REQUEST_URI} [NC]
    #RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^.*$ /main.php

    Sigh. Does anyone spot the mistake?

    Greetings
    DH2006
    Last edited by DH2006; 07-14-2009 at 09:16 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •