summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormakoto kuwata <kwa@kuwata-lab.com>2011-03-20 14:50:02 +0900
committermakoto kuwata <kwa@kuwata-lab.com>2011-03-20 14:58:32 +0900
commit0a7b4be8a40fbcb8d6ca5400b99efcf93e3f1267 (patch)
tree582a1c6f79c77ffb4e920a8118bb6902736bbe02
parente9c23b25a91126fc3246f1871a22e26b89ec2b17 (diff)
downloaderubis-0a7b4be8a40fbcb8d6ca5400b99efcf93e3f1267.tar.gz
[enhance] 'index.cgi' to handle access to directories
-rw-r--r--public_html/_htaccess4
-rwxr-xr-xpublic_html/index.cgi7
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