View Single Post

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

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:
>>>
>>>
>>>>Hello,
>>>>After reading the URL rewriting guide and several other documents, I
>>>>still haven't figured this out.
>>>>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
>>>>
>>>>So, assuming the original URL is domain.com/page.html
>>>>here are my last two (failed) attempts:
>>>># Attempt 1:
>>>># enable the rewrite module
>>>>RewriteEngine on
>>>>
>>>># use static html file if exists (from static/)
>>>>RewriteRule ^(.*)\.html$ $1 [C,E=WasHTML:yes]
>>>>
>>>>RewriteCond static%{REQUEST_FILENAME}.html -f
>>>>RewriteRule ^(.*)$ static$1.html [S=1]
>>>
>>>Did you try the following at all?
>>>
>>>RewriteCond static/%{REQUEST_FILENAME}.html -f
>>>RewriteRule ^(.*)$ static/$1.html [S=1]

>>
>> I just tried that, but it did not work either unfortunately.
>> What exactly is in "%{REQUEST_FILENAME}" if, let's say the URL is
>> http://domain.com/page.html
>> shouldn't that be "page.html"? Or "/page.html"?
>>
>> still confused :(

>
> Umm.. neither... more like: "/home/user/www/page.html", so change to this:
>
> RewriteCond static%{REQUEST_URI} -f
> RewriteRule ^(.*)$ static/$1.html [S=1]


Still not :(
I tried this, which seems logical to me (note the comments):
# remove .html extension, chain with next rule (/page.html -> /page)
RewriteRule ^(.*)\.html$ $1 [C,E=WasHTML:yes]
# rewrite to /static/page.html if exists, skip next rule (/page -> /static/page.html)
RewriteCond /static$1.html -f
RewriteRule ^(.*)$ /static/$1.html [S=1]
# if previous failed, but first rule matched, rewrite to .php extension (/page -> /page.php)
RewriteCond %{ENV:WasHTML} ^yes$
RewriteRule ^(.*)$ $1.php

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
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?

thanks :)