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 6362897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:58:00+00:00 2026-05-24T23:58:00+00:00

Is it possible to apply a .htaccess rewrite-rule on an already rewritten URL? Example:

  • 0

Is it possible to apply a .htaccess rewrite-rule on an already rewritten URL?

Example:
I want to resize my pictures with timthumb.php (most recent version, so there should be no security flaw any more). But the URL should look fine, therefore I created this rewrite-rule:

RewriteRule ^rz/(.*)x(.*)/r/(.*) /themes/Nerdtalk/timthumb.php?src=$3&h=$2&w=$1&q=80

This rule is working fine, but before starting timthumb.php which may re-direct to a cached file, I want Apache to check, if the file exists and let Apache redirect to the cached file, so timthumb.php won’t be started.
Therefore I created this ruleset:

RewriteCond %{SCRIPT_FILENAME} timthumb.php
RewriteCond %{QUERY_STRING} src=(.*)\.(png|jpe?g)&h=([0-9]+)&w=([0-9]+)&q=([0-9]+)
RewriteCond %{DOCUMENT_ROOT}/cache/%1-%4-%3-1-%5.%2 -f
RewriteRule ^.* /cache/%1-%4-%3-1-%5.%2 [L]
  1. Can an already rewritten URL be rewritten a second time?

  2. Is the second part correct?

  3. If there is a possibility to merge these two rulesets, can you please tell me how?

  • 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-24T23:58:01+00:00Added an answer on May 24, 2026 at 11:58 pm

    Can an already rewritten URL be rewritten a second time?

    Yes. When rewrite occurs (rule with the [L] flag or end of htaccess), mod_rewrite goes to next iteration and starts matching all rules again from start. That’s why you need to build your rules with rewrite loop in mind (especially if you use this sort of pattern ^(.*)$ for matching).

    If you write a rule without [L] flag, then rewrite continues on the same iteration, so any rules placed below current may rewrite URL again to a completely different.

    Is the second part correct?

    I would say Yes (although not checking on the actual Apache). I’m just not sure about first rewrite condition (just never used %{SCRIPT_FILENAME} myself so unsure how exactly it works) — I would use %{REQUEST_URI} timthumb\.php$ or something like that.

    The only thing that I would add is ? at rewrite target to get rid of newly created (1 rule above) query string: RewriteRule ^.* /cache/%1-%4-%3-1-%5.%2? [L]. But it should work fine as is now.

    If there is a possibility to merge these two rulesets, can you please
    tell me how?

    Place them one after another in the same order you have here. You cannot make it a single rule as 2nd rule will only work if thumbnail is already cached.

    If it will not work straight away (as Apache’s variables (%{SCRIPT_FILENAME}, %{QUERY_STRING} etc) may not have proper values straight away) try adding [L] flag to first rewrite rule — it will force next iteration which populates those variables with proper values for sure, and, depending on the rest of your rules that you may have before this one, it will reach 2nd ruleset where 2nd rewrite will occur.

    If you want — you can rewrite it completely to check and serve cached file straight away (if present) and then (if still nothing) rewrite image to be processed by timthumb.php, but that will do exactly the same job as aforementioned rules, just a bit differently.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to apply the Replication mechanism on single MySQL server? I want
Is it possible to apply HTTP header directives based on the URL's query string
Is it possible to apply a WHERE clause on a SubSonic query? For example,
I am wondering wether it's possible to use .htaccess to rewrite a folder name.
Is it possible to apply a style to the outer div in this example,
Is it possible to apply / create a YUI Button by using an element's
Is it possible to apply a css(3) style to a label of a checked
Is it possible to apply (and remove) Windows group policy settings using .NET? I
Is it possible to apply reactive framework (Rx) in MVC application? or is it
Is it possible to apply trigger on any table in information_schema?

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.