From 0a7b4be8a40fbcb8d6ca5400b99efcf93e3f1267 Mon Sep 17 00:00:00 2001 From: makoto kuwata Date: Sun, 20 Mar 2011 14:50:02 +0900 Subject: [enhance] 'index.cgi' to handle access to directories --- public_html/_htaccess | 4 ++-- public_html/index.cgi | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/public_html/_htaccess b/public_html/_htaccess index 99a215c..1eec816 100644 --- a/public_html/_htaccess +++ b/public_html/_htaccess @@ -4,5 +4,5 @@ RewriteEngine on RewriteRule \.(rhtml|cache)$ - [R=404,L] ## rewrite only if requested file is not found RewriteCond %{SCRIPT_FILENAME} !-f -## handle request to *.html by index.cgi -RewriteRule ^.*\.html$ /~yourname/index.cgi +## handle request to *.html and directories by index.cgi +RewriteRule (\.html|/|^)$ /~username/index.cgi diff --git a/public_html/index.cgi b/public_html/index.cgi index 7d8a8b1..4480cd6 100755 --- a/public_html/index.cgi +++ b/public_html/index.cgi @@ -60,8 +60,13 @@ class ErubisHandler filepath = basepath =~ /\A\/(~[-.\w]+)/ \ ? File.join(File.expand_path($1), "public_html", $') \ : File.join(document_root, basepath) - filepath.gsub!(/\.html\z/, '.rhtml') or # expected '*.html' + if filepath =~ /\.html\z/ # expected '*.html' + filepath.gsub!(/\.html\z/, '.rhtml') + elsif filepath[-1] == ?/ # directory index + filepath += 'index.rhtml' + else raise HttpError.new(500, 'invalid .htaccess configuration.') + end File.file?(filepath) or # file not found raise HttpError.new(404, "#{basepath}: not found.") basepath != env['SCRIPT_NAME'] or # can't access to index.cgi -- cgit v1.2.1