How to rewrite to static file only if it exists (.htaccess)
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 mat开发者_开发问答ch :(.
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]
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]
精彩评论