Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We want to serve up an image as apache is so good at doing, and when the client requests a thumbnail, the request will look like the following: [http://host/photos/im/image_w200.jpg] (w200 is the requested width of the thumbnail).

Sometimes the thumbnails will not exist. When they don't exist we want apache to forward the request to our application. That request will look like [http://host/create_thumbnail?file=image_w250.jpg]. The app will create the thumbnail, and redirect back to the original request.

This worked fine when I had normal files and directories in /home/dev/x/y/mediadir. However /home/dev/x/y/mediadir/photos is now a symbolic link to the /home/dev/photos directory. So now, even when the file exists, it is always passing the !-f RewriteCond and rewriting to thumbnail the photo.

Things I have tried:

  • the server has access to the symlink dirs. When I take out the rewrite block, it works fine
  • I have tried !-l, !-F, and !-U. !-U serves the file when it exists, but when it doesn't exist apache doesn't rewrite the request. !-l, and !-F do the same thing as !-f

Anyone have any suggestions?

<VirtualHost *:443>

        #... cut ...

    RewriteLog /home/dev/logs/rewrite.log
    RewriteLogLevel 3

    Alias /media/ /home/dev/x/y/mediadir/
    <Directory /home/dev/x/y/mediadir>
        Order allow,deny
        Allow from all
        Options FollowSymLinks

        RewriteEngine on
        RewriteCond photos/../$ !-f
        RewriteRule ^photos/../(.+)$ https://%{HTTP_HOST}/create_thumbnail?file=$1
    </Directory>
share|improve this question

2 Answers 2

up vote 2 down vote accepted

Instead of using one RequestCond (RewriteCond photos/../$ !-f), I used two. The first to check if the REQUEST_FILENAME matches the regex, and the second to check that the file doesn't exist. This is working well for me.

    RewriteCond %{REQUEST_FILENAME} photos/../.+
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^photos/../(.+)$ https://%{HTTP_HOST}/create_thumbnail?file=$1
share|improve this answer
    
Thanks a ton sir. –  Euloiix Jul 9 at 11:09

I'm kind of confused what your paths are, because you refer to /mediadir, but there is no /mediadir (referenced from root; not in the file system, nor in apache). So I don't really know what you mean, but perhaps you can fix it by adding:

<Directory /path/to/photos/>
    Order allow,deny
    Allow from all
</Directory>

What does your rewrite log say?

share|improve this answer
    
I see what you mean by the confusing nature of how I had my directories, so I fixed the directory names, and the references to them in my question. I will look into adding the <Directory directive. –  Ballpark May 5 '11 at 22:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.