Forum Moderators: phranque
But the problem is I want it in a different directory
like
/htmlcache/
and would like .htaccess to do the check, if the page exists in the /htmlcache directory fetch it and display it.
I am not very good in .htaccess so can any on help me with this.
I even don't know whether it is possible or not :).
Thanks
File exists check:
RewriteCond %{REQUEST_FILENAME} -f
It can be functionally replaced with
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f
RewriteCond %{DOCUMENT_ROOT}/subdirectory%{REQUEST_URI} -f
# Rewrite /<name>.html requests to /subdirectory/<name>.htm files if they exist
RewriteCond %{DOCUMENT_ROOT}/subdirectory/$1.htm -f
RewriteRule ^([^.]+)\.html$ /subdirectory/$1.htm [L]
Jim
# Check if HTML page exists in HTMLCacheDir if exists display it.
RewriteCond %{REQUEST_URI} ([[:print:]])\.html
RewriteCond %{DOCUMENT_ROOT}/htmlcache%{REQUEST_URI} -f
RewriteRule (.*) /htmlcache%{REQUEST_URI} [L]
# Check for index.html pages in HTMLCacheDir incase of directory .
RewriteCond %{DOCUMENT_ROOT}/htmlcache%{REQUEST_URI} -d
RewriteCond %{DOCUMENT_ROOT}/htmlcache%{REQUEST_URI}index.html -f
RewriteRule (.*) /htmlcache%{REQUEST_URI}index.html [L]
Thanks for the help.
Prabhanjan Panigrahi
RewriteCond %{REQUEST_URI} ([[:print:]])\.html
Also, be aware that you should test the URL-path in the RewriteRule itself when possible, because adding an extra RewriteCond to do it just slows down your code.
Jim
Since what you are testing is a URL, only printable characters can/will appear anyway. So you could just as well use the pattern "^([^.]+)\.html$" there. However, if you use dots in directory names, it would need to be "^(.+)\.html$".
Jim
[edited by: jdMorgan at 2:22 pm (utc) on July 18, 2008]
# Check if HTML page exists in HTMLCacheDir if exists display it.
RewriteCond %{DOCUMENT_ROOT}/htmlcache/$1.html -f
RewriteRule ^([^.]+)\.html$ /htmlcache/$1.html [L]
# Check for index.html pages in HTMLCacheDir incase of directory and display it.
RewriteCond %{DOCUMENT_ROOT}/htmlcache/$1 -d
#RewriteCond %{DOCUMENT_ROOT}/htmlcache/$1/index.html -f
RewriteRule ^(.*)$ /$1/index.html [L]
Thanks,
Prabhanjan Panigrahi