tags:

views:

29

answers:

1

Hello.

I would like apache to render %{DOCUMENT_ROOT}/cache/%1.html

if %1 is the request path. My whole site is in a sub directory called cache_test and I have the following .htaccess file. But the RewriteRule on line 7 and 11 won't match :(.

Thank you in advance for any advance! Kind regards, Nicklas

 1 RewriteEngine   On
 2 RewriteBase     /cache_test/
 3
 4 RewriteCond     %{THE_REQUEST} ^(GET|HEAD)
 5 RewriteCond     %{REQUEST_URI} ^/([^.]+)$
 6 RewriteCond     %{DOCUMENT_ROOT}/cache/%1.html -f
 7 RewriteRule     ^/[^.]+$ /cache/%1.html [QSA,L]
 8
 9 RewriteCond     %{THE_REQUEST} ^(GET|HEAD)
10 RewriteCond     %{DOCUMENT_ROOT}/cache/index.html -f
11 RewriteRule     ^/$ /cache/index.html [QSA,L]
12
13 RewriteRule     (.*/cache_test)$ $1/
14 RewriteRule     ^$ index.html [QSA]
15 RewriteRule     ^([^.]+)$ $1.html [QSA]
16 RewriteCond     %{REQUEST_FILENAME} !-f 
17 RewriteRule     ^(.*)$ dispatch.fcgi [QSA,L]
A: 

RewriteBase + DOCUMENT_ROOT ==> troubles...

I'm not in a position to test right now, you might want to check wether this works, change:

6 RewriteCond     %{DOCUMENT_ROOT}/cache/%1.html -f

To:

6 RewriteCond     ../cache/%1.html -f

And if not, I see no other option but to forget about the advantages of RewriteBase & drop that.

On a side note, why do you need this?

RewriteRule     ^$ index.html [QSA] 
Wrikken
Thank for your reply Wrikken!I tried to use the relative path as you pointed out and it didn't work. About the "^$ index.html [QSA]"-line I'm not sure. I must admit that mod_rewrite is far from my strong side. Line 13 to 17 are all to get Apache to route everything to rails (through fcgi).Do you have any tips on how the file might look like after converting it away from RewriteBase?Thank you, and tank you again in advance.Kind regards,Nicklas
Nicklas
If you don't add a rewritebase (http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritebase), most of your patterns to match against need th cache_test path at the front (^/?cache_test/)
Wrikken