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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:54:19+00:00 2026-05-30T03:54:19+00:00

I’ve just set up static page caching using Zend_Cache_Backend_Static to serve cached html files

  • 0

I’ve just set up static page caching using Zend_Cache_Backend_Static to serve cached html files in my application, which is working great. The only concern I have is down to the way it caches files with $_GET parameters. Because it automatically creates a folder structure which maps to the supplied URL route, is this a potential security risk in cases where large numbers of $_GET parameters may be deliberately appended to existing pages? Either hitting a maximum directory depth or a maximum file length?

For example: At the moment I’m caching my pages into /public/cache/static/ so using the standard router /module/controller/action/param1/val1/param2/val2 or standard query string /module/controller/action?param1=val1&param2=val2 would create the following directory structures:

/public/cache/static/module/controller/action/param1/val1/param2/val2.html 
/public/cache/static/module/controller/action?param1=val1&param2=val2.html

Allowing people access to creating a directory structure in this way (however limited) worries me slightly. Both Zend_Cache_Backend_Static and the corresponding Zend_Cache_Frontend_Capture must both be set in the ini file not via Zend_Cache factory and don’t appear to have any setup options.

Could it just be a case of replacing the default router with custom routes that limit the number of $_GET variables? Is this possible or would I need to specify exactly the variables I needed for each route (not the end of the world but a bit more limiting)

Update:

So the existing rewrite rule to handle the static cache is as follows:

RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{DOCUMENT_ROOT}/cached/index.html -f
RewriteRule ^/*$ cached/index.html [L]

RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{DOCUMENT_ROOT}/cached/%{REQUEST_URI}\.html -f
RewriteRule .* cached/%{REQUEST_URI}\.html [L]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteRule ^.*$ index.php [NC,L]

If the request hits a page in the static cache it will send that html page. If not it will hit Zend Framework and generate it.

I could add the following to the start:

RewriteCond %{QUERY_STRING} \S
RewriteRule [^\?]+ /$0? [R=301,L]

Which will wipe my query string altogether. This is fine as I can still pass $_GET variables in using the URL path method of Zend Framework (which I have also limited by providing very explicit routes). But is it possible to do this without redirecting?

  • 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-30T03:54:20+00:00Added an answer on May 30, 2026 at 3:54 am

    OK, so the RewriteRule stripping the query string will work without a redirect.

    The issue (I suspect), is that Zend_Cache_Backend_Static is using $_SERVER[‘REQUEST_URI’] somewhere along the line and therefore getting access to the original filename. My knowledge of mod_rewrite is pretty slim and I didn’t realise that this value wasn’t altered.

    So, to prevent files and directories being created by massive query strings I’ve had to do the following things:

    Firstly for standard query strings:

    Strip the query string at the start of my mod_rewrite, without redirecting:

    RewriteCond %{QUERY_STRING} \S
    RewriteRule [^\?]+ /$0?
    

    In my index.php I’m then changing the $_SERVER[‘REQUEST_URI’] to match the redirect, by stripping the query string, which means I don’t need to hack ZF any longer:

    $queryIndex = strpos($_SERVER['REQUEST_URI'], '?');
    if($queryIndex !== false) {
        $_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'], 0, $queryIndex);
    }
    

    This will now prevent ANY query string from being interpreted by my application. To pass variables to pages I am therefore using Zend Framework url path parameters. To prevent these from creating excessively deep cache folders, I’ve replaced the default route with a few very explicitly defined routes in the Bootstrap:

    $frontController = Zend_Controller_Front::getInstance(); 
    $router = $frontController->getRouter();
    
    $route = new Zend_Controller_Router_Route(
        ':module/:controller/:action',
        array(
            'module' => 'default',
            'controller' => 'index',
            'action' => 'index'
        )
    );
    
    $router->addRoute('default', $route);
    
    $route = new Zend_Controller_Router_Route(
        'article/:alias',
        array(
            'module' => 'default',
            'controller' => 'article',
            'action' => 'index',
            'alias' => ''
        )
    );
    
    $router->addRoute('article', $route);
    

    Here, I’ve replaced the default route so no additional parameters are allowed. Any actions which do require parameters therefore have to be explicitly set, for example in my second route. This means there could potentially be a lot of defined routes. Thankfully this is not the case in my particular application.

    A way around restricting the routes so much and allowing some GET params via ZF URL paths is to set a limit on the number of slashes in the REQUEST_URI, effectively limiting the max directory depth of the static page cache (10 below). This can also be altered in index.php:

    if(substr_count($_SERVER['REQUEST_URI'], '/') > 10) {
        preg_match_all("/\//", $_SERVER['REQUEST_URI'] ,$capture, PREG_OFFSET_CAPTURE);
        $_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'], 0, $capture[0][9][1]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm making a simple page using Google Maps API 3. My first. One marker
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.