Anyone know why this mod_rewrite RewriteCond doesn't work as expected?
Permalink
I am trying to come up with a way to serve up static version of pages that C5 is used to maintain to gain the most speed possible for my C5 created sites.
Toward that goal I have come up with the following mod_rewrite gibberish :) to redirect requests to static page versions inside a mycache directory.
But for the life of me I can't figure out why the tail end of the REQUEST_URI containing the pretty URL version of a file name is not captured into %1.
Here is the code...
Anybody got a clue as to why it isn't being captured?
The value that ends up in %1 is...well...empty. Nothing.
In other words a REQUEST_URI of say /things-to-do should capture "things-to-do" into %1 so that I can then turn it into things-to-do.html in the RewriteRule.
But nothing.
I thought I would ask here first before going on more Apache oriented forums to ask there.
Any insight would be appreciated.
Thanks.
Carlos
Toward that goal I have come up with the following mod_rewrite gibberish :) to redirect requests to static page versions inside a mycache directory.
But for the life of me I can't figure out why the tail end of the REQUEST_URI containing the pretty URL version of a file name is not captured into %1.
Here is the code...
RewriteCond %{REQUEST_METHOD} GET RewriteCond %{REQUEST_URI} /(.*) RewriteCond %{DOCUMENT_ROOT}/mycache/%1.html -f RewriteRule ^/*$ mycache/%1.html [last]
Anybody got a clue as to why it isn't being captured?
The value that ends up in %1 is...well...empty. Nothing.
In other words a REQUEST_URI of say /things-to-do should capture "things-to-do" into %1 so that I can then turn it into things-to-do.html in the RewriteRule.
But nothing.
I thought I would ask here first before going on more Apache oriented forums to ask there.
Any insight would be appreciated.
Thanks.
Carlos
Ahem...cough, cough...well..ahem...regarding C5 having pretty good caching...I...well...I beg to differ :).
C5's caching implementation is presently broken. The consensus on various threads that I have read is that it is actually faster to disable C5 caching altogether.
Until that is fixed it is advisable to find another caching mechanism.
Based on various forum responses to caching problems from those that are on the core team Fernandos I am not at all certain that C5's caching serves up complete static pages.
C5's caching is based on Zend Cache which optimizes PHP code (among other things) to run faster but which does not serve up static pages in their entirety.
What I am working on is a means of serving up static pages in such a way that it completely bypasses C5 altogether. I mean completely. Such that you could blow away C5 and still have a site be served up from a store of static pages. Speed wise that's almost as fast as it gets.
I don't think C5 does that in their caching.
Anyway if anyone has any insight on why my mod_rewrite rule is not capturing what I want into the %1 backreference I'd love to hear it otherwise I'll ask on more Apache related forums.
Thanks.
Carlos
C5's caching implementation is presently broken. The consensus on various threads that I have read is that it is actually faster to disable C5 caching altogether.
Until that is fixed it is advisable to find another caching mechanism.
Based on various forum responses to caching problems from those that are on the core team Fernandos I am not at all certain that C5's caching serves up complete static pages.
C5's caching is based on Zend Cache which optimizes PHP code (among other things) to run faster but which does not serve up static pages in their entirety.
What I am working on is a means of serving up static pages in such a way that it completely bypasses C5 altogether. I mean completely. Such that you could blow away C5 and still have a site be served up from a store of static pages. Speed wise that's almost as fast as it gets.
I don't think C5 does that in their caching.
Anyway if anyone has any insight on why my mod_rewrite rule is not capturing what I want into the %1 backreference I'd love to hear it otherwise I'll ask on more Apache related forums.
Thanks.
Carlos
So to your actual problem, you're having the static html mirror of your site inside of "/mycache" and want it to get rewritten to /filename.html, ok.
The problem is that you're not encasing the regular expression part of the URL in parentheses, that's why we want store whatever value was found there for later use.
Here's your fix, just replace the RewriteRule, you could put it all into an if too, to make it friendlier to apache.
(untested, don't blame me if it blows up your building :) )
That's right c5's full page cache isn't perfect, but it serves it's purpose and is as good as the zend library behind it. I've looked through the code, so I know what happens internally. It's pretty interesting actually. You're surely not alone with your opinion regarding c5's caching. And of course static html mirrors of your site get served faster than anything with php. You could have mentioned that you're usinghttp://www.mesuva.com.au/blog/technical-notes/an-extra-cache-for-co... it would have made it easier for me to understand your background. I assumed you're a rookie, that's why I suggested that.
The problem is that you're not encasing the regular expression part of the URL in parentheses, that's why we want store whatever value was found there for later use.
Here's your fix, just replace the RewriteRule, you could put it all into an if too, to make it friendlier to apache.
(untested, don't blame me if it blows up your building :) )
<IfModule mod_rewrite.c> RewriteRule ^mycache/(.*)$ /$1\.html [last] </IfModule>
That's right c5's full page cache isn't perfect, but it serves it's purpose and is as good as the zend library behind it. I've looked through the code, so I know what happens internally. It's pretty interesting actually. You're surely not alone with your opinion regarding c5's caching. And of course static html mirrors of your site get served faster than anything with php. You could have mentioned that you're usinghttp://www.mesuva.com.au/blog/technical-notes/an-extra-cache-for-co... it would have made it easier for me to understand your background. I assumed you're a rookie, that's why I suggested that.
(this lighbox sucks.. I can't see your message when I type an answer)
Yeah...I can't stand this forum software either. Especially irritating is the way Details are hidden behind a link I must click on in order to know who I am responding to or how old a post is.
But...we don't have much say in the matter so we have to make do with what we got I guess :).
Carlos
But...we don't have much say in the matter so we have to make do with what we got I guess :).
Carlos
Full Ack!
Hi Fernandos,
Thanks very much for your attempt to help me with my RewriteRules but...well...I am not sure you understand what it is that I am trying to do through the rules I posted.
Your "fix" actually rewrites url's of the typewww.www.domain.com/mycache/somepage... towww.www.domain.com/somepage.html... if I am not mistaken.
What I need is a way to capture the QUERY_STRING such that I can then use it as the basis for rewriting it and adding a .html extension.
In other words I need to be able to rewrite (internally) a url of the typehttp://www.domain.com/some-page/ orhttp://www.domain.com/some-page towww.www.domain.com/mycache/some-page.html...
And I need to be to use the "some-page" part of the url in a RewriteCond so that I can check for the existance of said html file before the RewriteRule executes.
I am trying a couple of things and will let you know if I get it to work.
Thanks again for your input Fernandos.
By the way I am not using the caching you indicate that I am using. I looked at it but never said I was using it. Just so you know.
Carlos
Thanks very much for your attempt to help me with my RewriteRules but...well...I am not sure you understand what it is that I am trying to do through the rules I posted.
Your "fix" actually rewrites url's of the typewww.www.domain.com/mycache/somepage... towww.www.domain.com/somepage.html... if I am not mistaken.
What I need is a way to capture the QUERY_STRING such that I can then use it as the basis for rewriting it and adding a .html extension.
In other words I need to be able to rewrite (internally) a url of the typehttp://www.domain.com/some-page/ orhttp://www.domain.com/some-page towww.www.domain.com/mycache/some-page.html...
And I need to be to use the "some-page" part of the url in a RewriteCond so that I can check for the existance of said html file before the RewriteRule executes.
I am trying a couple of things and will let you know if I get it to work.
Thanks again for your input Fernandos.
By the way I am not using the caching you indicate that I am using. I looked at it but never said I was using it. Just so you know.
Carlos
I've overseen the request_uri part when typing the answer..
I think you've just replaced $ with % accidentally.
% is used for server variables only. $N for backreferences where N is 0-9
however I think this should do it.. not sure though, you're welcome to report back if it works.
here's a cheat-sheet, just for the case.
http://www.addedbytes.com/cheat-sheets/download/mod_rewrite-cheat-s...
(I'm out of training a bit, have worked more with nginx rules the last weeks than with apache rules.)
I think you've just replaced $ with % accidentally.
% is used for server variables only. $N for backreferences where N is 0-9
however I think this should do it.. not sure though, you're welcome to report back if it works.
RewriteCond %{REQUEST_METHOD} GET RewriteCond %{REQUEST_URI} /(.*) RewriteCond %{DOCUMENT_ROOT}/mycache/$1.html -f RewriteRule ^/(.*)$ mycache/$1.html [last]
here's a cheat-sheet, just for the case.
http://www.addedbytes.com/cheat-sheets/download/mod_rewrite-cheat-s...
(I'm out of training a bit, have worked more with nginx rules the last weeks than with apache rules.)
Thanks very much for your fix Fernandos!
While it didn't work exactly as you had it, the fix was in what you wrote, and with some minor changes it worked!
Here is what finally works!
The "########" are in the above code because the form software won't keep linebreaks in the code as written.
The above will serve up static version of site pages if found in the mycache directory. If they are not there it will serve up regular C5 generated pages. Login works just fine.
This approach still needs a lot of refining in that the browser cache has to be cleared when a page is deleted from the mycache directory before a new page is served up by C5. I need to disable browser caching perhaps.
Also if someone makes a change to a page there is too much manual fiddling necessary to have this approach be very practical for end clients in that someone needs to go into the mycache directory and delete the static file version of a page that was just edited.
But for now...I don't care in that my C5 sites are now going to be blazingly fast and my clients will be very happy (I make most changes for my clients as they really don't want to mess with even learning how to use C5 at this point in time)!
I'll work on a C5 interface Add On to allow end users to indicate which pages to serve up in static form and deleting those from the mycache directory that have modification dates later than the file dates.
By the way nice cheat sheet. Here is another one I found yesterday which is full of nice examples (http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html)
Carlos
PS. HOW CAN I KEEP THE DETAILS OPEN WITHOUT HAVING TO CLICK ON THAT LINK EVERY TIME I RESPOND TO SOMEONE?? ANYBODY??
While it didn't work exactly as you had it, the fix was in what you wrote, and with some minor changes it worked!
Here is what finally works!
RewriteCond %{REQUEST_METHOD} GET RewriteCond %{REQUEST_URI} / RewriteCond %{DOCUMENT_ROOT}/mycache/home.html -f RewriteRule ^/*$ mycache/home.html [last] ########## RewriteCond %{REQUEST_METHOD} GET RewriteCond %{DOCUMENT_ROOT}/mycache/$1.html -f RewriteRule ^(.*)$ mycache/$1.html [last] ########## RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [last]
The "########" are in the above code because the form software won't keep linebreaks in the code as written.
The above will serve up static version of site pages if found in the mycache directory. If they are not there it will serve up regular C5 generated pages. Login works just fine.
This approach still needs a lot of refining in that the browser cache has to be cleared when a page is deleted from the mycache directory before a new page is served up by C5. I need to disable browser caching perhaps.
Also if someone makes a change to a page there is too much manual fiddling necessary to have this approach be very practical for end clients in that someone needs to go into the mycache directory and delete the static file version of a page that was just edited.
But for now...I don't care in that my C5 sites are now going to be blazingly fast and my clients will be very happy (I make most changes for my clients as they really don't want to mess with even learning how to use C5 at this point in time)!
I'll work on a C5 interface Add On to allow end users to indicate which pages to serve up in static form and deleting those from the mycache directory that have modification dates later than the file dates.
By the way nice cheat sheet. Here is another one I found yesterday which is full of nice examples (http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html)
Carlos
PS. HOW CAN I KEEP THE DETAILS OPEN WITHOUT HAVING TO CLICK ON THAT LINK EVERY TIME I RESPOND TO SOMEONE?? ANYBODY??
nice! glad you fixed it at the end :)
can you mark it as answer then? :P
hmm maybe you can embed your changes into the dashboard so that people can find it on the same place as c5's caching. And clearing the cache would clear your or the c5 cache.
You could create a fork of c5 on github and if your code is good enough Andrew may merge it into the next c5 version..who knows..
This is related to UX:
When I look through the code of projects made by developers very often I always find the same pattern. The code is more complex than neccesary and also the ui is full of options, because developers want to show their skill by providing a fully customizable app.
Nothing wrong with that as long as their skill stays in the code, because that's what developers can, code. User Interface Design is usally underrated.
All users care about is that it must simply work.
It's possible to set good defaults and let the other parameters detect automatically. Of course giving some power to the user through simple on/off switches is still cool.
PS: You can fix that manually, using greasemonkey and some javascript to modify the details pane to an open state by default.. sucks.. but there is no other easy way..
can you mark it as answer then? :P
hmm maybe you can embed your changes into the dashboard so that people can find it on the same place as c5's caching. And clearing the cache would clear your or the c5 cache.
You could create a fork of c5 on github and if your code is good enough Andrew may merge it into the next c5 version..who knows..
This is related to UX:
When I look through the code of projects made by developers very often I always find the same pattern. The code is more complex than neccesary and also the ui is full of options, because developers want to show their skill by providing a fully customizable app.
Nothing wrong with that as long as their skill stays in the code, because that's what developers can, code. User Interface Design is usally underrated.
All users care about is that it must simply work.
It's possible to set good defaults and let the other parameters detect automatically. Of course giving some power to the user through simple on/off switches is still cool.
PS: You can fix that manually, using greasemonkey and some javascript to modify the details pane to an open state by default.. sucks.. but there is no other easy way..
I don't know how I am going to try and fit it into the C5 interface yet but you've got some good ideas as to where it might fit Fernandos (although getting into a forked version to make some changes is a bit much for me at this time I think).
Awesome if I can do what I want with that nasty, irritating, little pesky detail of having to click on Details to...well...see the name and date of someone posting. I'll look into that for sure.
Don't know why people have been all but ignoring my questions about how to make the Details appear again but oh well...I'll just take care of it myself.
I like that.
Carlos
Awesome if I can do what I want with that nasty, irritating, little pesky detail of having to click on Details to...well...see the name and date of someone posting. I'll look into that for sure.
Don't know why people have been all but ignoring my questions about how to make the Details appear again but oh well...I'll just take care of it myself.
I like that.
Carlos
So, if you enable "full page caching" c5 won't open any db connection and directly serve statically cached pages from your cache instead. This would improve your page speed a lot too and save you from writing rewrite rules. To further optimize your site there is a lot of stuff you can do.. but a guy made some good effort to automate that for you.
Checkout "Miser" to optimize your site.
http://www.concrete5.org/community/forums/customizing_c5/miser-web-...