Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6009891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:02:12+00:00 2026-05-23T02:02:12+00:00

I am writing a on-the-fly thumbnail creator for a CMS and need to dynamically

  • 0

I am writing a on-the-fly thumbnail creator for a CMS and need to dynamically check if a file exists. I currently have created an htaccess file that checks if the file you are requesting exists, but need it to be a bit more advanced and “create” the file check based on the submitted URLs options.

Here is what I currently have (based on image ID, not name):

RewriteEngine on

#Check for file existence here and forward if exists
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)-([0-9]+)-([0-9]+)(-(crop))?\.jpg$ thumbnail.php?id=$1&w=$2&h=$3&c=$4 [L,QSA]

Based on this URL:

this-is-the-image-name.gif?w=200&h=100&c=true

An htaccess file checks if this file exists:

this-is-the-image-name-gif-200-100-crop.jpg

If it doesn’t exists it RewriteRules user to:

thumbnail.php?name=this-is-the-image-name&type=gif&w=200&height=100&c=true

“Crop” is optional, so without it the previous URLs look like this:

this-is-the-image-name.gif?w=200&h=100
this-is-the-image-name-gif-200-100.jpg
thumbnail.php?name=this-is-the-image-name&type=gif&w=200&height=100

Basically, I need the RewriteCond to check if a file exists based on a filename that it creates based on the REQUEST_FILENAME. Any ideas?

Something like this:

RewriteCond ^([a-zA-Z0-9-]+).(jpg|gif|png)?w=([0-9]+)&h=([0-9]+)(&c=(-crop))?\.jpg$ %$1-$2-$3-$4-$6.jpg !-f

Not even sure if this is possible… in which case I would have it forward ALL requests to the PHP file, but since the PHP has a lot of overhead I thought this would be speedier.

Thank you very much for any help in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:02:13+00:00Added an answer on May 23, 2026 at 2:02 am

    from the rewritecond docs

    RewriteRule backreferences: These are
    backreferences of the form $N (0 <= N
    <= 9), which provide access to the
    grouped parts (in parentheses) of the
    pattern, from the RewriteRule which is
    subject to the current set of
    RewriteCond conditions..

    RewriteCond
    backreferences: These are
    backreferences of the form %N (1 <= N
    <= 9), which provide access to the
    grouped parts (again, in parentheses)
    of the pattern, from the last matched
    RewriteCond in the current set of
    conditions.

    # file is a gif
    RewriteCond %{REQUEST_FILENAME} .gif$
    
    # capture the and params in () backreferences
    RewriteCond %{QUERY_STRING} w=(200)&h=(100)&c=true
    
    # only rewrites for files that do not exist
    RewriteCond %{REQUEST_FILENAME}-gif-%1-%2-crop.jpg !-f
    
    # this rewrites not found thumbs to your php script
    RewriteRule %.*$ thumbnail.php?name=%{REQUEST_FILENAME}&type=gif&w=%1&height=%2&c=true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I am writing an on-the-fly thumbnail generator for a CMS and I am
I'm writing a Javascript function that would manipulate an array written on-the-fly and sent
I am currently writing a linux application in C that reads from a configuration
The following code transfers an image that is created on the fly from a
I'm writing .NET On-the-Fly compiler for CLR scripting. And have a dilemma: is it
I have a game consisting of ships that fly around on a 2d grid.
I'm writing a simple html page creator that will generate html code on customized
I'm writing text-images on the fly with PHPs imagettftext , which works fine so
I'm writing an application to do proxying and rewriting of webpages on the fly
Writing a JSP page, what exactly does the <c:out> do? I've noticed that the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.