View Single Post

  #9 (permalink)  
Old 09-30-2004
Justin Koivisto
 
Posts: n/a
Default Re: mod_rewrite On-the-fly Content-Regeneration not working

DrTebi wrote:

> On Thu, 30 Sep 2004 15:55:12 +0000, Justin Koivisto wrote:
>
>
>>DrTebi wrote:
>>
>>>On Thu, 30 Sep 2004 14:50:09 +0000, Justin Koivisto wrote:
>>>
>>>>DrTebi wrote:
>>>>
>>>>>On Thu, 30 Sep 2004 13:13:50 +0000, Justin Koivisto wrote:
>>>>>
>>>>>>DrTebi wrote:
>>>>>>
>>>>>>
>>>>>>>Basically this what I am trying to approach:
>>>>>>>- User requests domain.com/page.html
>>>>>>>- mod_rewrite checks if requested page exists in
>>>>>>>domain.com/static/page.html
>>>>>>>- if page does exist, it's served
>>>>>>>- if it does not exist, mod_rewrite redirects to domain.com/page.php
>>>>>>>- domain.com/page.php generates domain.com/static/page.html

>>
>><snip bad info ;) >
>>
>>>Please tell me two things:
>>>1) what's the original before I do a rewrite,
>>>let's say of http://domain.com/page.html
>>>I assumed /page.html

>>
>>%{REQUEST_URI} = /page.html
>>
>>
>>>2) Once a rewrite took place, like stripping the .html
>>>from the request, is the next rule going to work on
>>>/page or still on /page.html?

>>
>>When you perform a RewriteRule, you are then working with the result of
>>the rule, not the original request anymore...
>>
>>
>>Here's how I think it should work for what you want to accomplish (turn
>>on rewrite log file and check if you want to see):
>>
>>User sends GET request to: http://domain.com/page.html
>> %{REQUEST_URI} = /page.html
>>
>>RewriteCond static%{REQUEST_URI} -f
>> If static/page.html is a file, do the next rule
>>
>>RewriteRule ^(.*)\.html$ static/$1.html [L]
>> Rewrite /page.html to /static/page.html, end processing (L flag)
>>
>>RewriteRule ^(.*)\.html$ $1.php [L]
>> Rewrite /page/html tp /page.php, end processing
>> This rule is only reached if no L flag was encountered above.

>
>
> Thank you so much for helping... your idea is very logical, but still does
> not work. The problem is simply looping:
> /page.html requested
> /static/page.html exists, redirect to /static/page.html
> /static.page.html requested
> /static/static/page.html does not exist
> /page.php
>
> Can you see that? I am pretty sure that's it. I have hacked together now
> ansomething that works, by having the user request .htm pages, and look
> for.html pages in the static directory:
> # Dynamic Caching 6 (this finally works ;))
> RewriteRule ^(.*)\.htm$ $1 [C,E=HTM:yes]
> RewriteCond %{DOCUMENT_ROOT}/static/%{REQUEST_URI}l -f
> RewriteRule ^(.*)$ static/$1.html [S=1]
> RewriteCond %{ENV:HTM} ^yes$
> RewriteRule ^(.*)$ $1.php
>
> This would go like this:
> page.htm requested
> page.htm rewritten to /page
> domain.com/static/page.html condition matches
> static/page.html requested
> end ;)
>
> And would the page not exist:
> page.htm requested
> page.htm rewritten to /page
> domain.com/static/page.html condition does not match
> page.php requested
> end
>
> Puhh! That was a hard one. It's a bit ugly now, but I will get used to it ;)
> Thanks for all your help!
>
> DrTebi
>


Ahh... simple logic error:

RewriteCond %{REQUEST_URI} !^/static
RewriteCond static%{REQUEST_URI} -f
RewriteRule ^(.*)\.html$ static/$1.html [L]

RewriteRule ^(.*)\.html$ $1.php [L]

That should actually do it. No need to tell it to skip or set
environment variables. ;)

--
Justin Koivisto - spam@koivi.com
http://www.koivi.com