Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-14-2009, 08:13 PM   PM User | #1
DH2006
New Coder

 
Join Date: May 2006
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
DH2006 is an unknown quantity at this point
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 08:16 PM..
DH2006 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:09 AM.


Advertisement
Log in to turn off these ads.