ref: 19649f556cc7781acfce5ba473d60e44e3904401
parent: 5d724cf1c450cd40ab8f112a5e643e1385e4c249
author: uriel <uriel@suckless.org>
date: Mon Jul 7 01:40:39 EDT 2008
Automatically redirect directory requests to the correct canonical address
--- a/bin/controller.rc
+++ b/bin/controller.rc
@@ -125,6 +125,7 @@
if not if(~ $#blogDirs 0) {
#echo 'Status: 404 Not Found\n\n' # should go before starting to print body
template.awk inc/404.tpl | rc $rcargs
+ dprint 'NOT FOUND: '$SERVER_NAME^$REQUEST_URI^' - '^$"HTTP_REFERER
}
if(! ~ $#blogDirs 0) {
@@ -150,7 +151,7 @@
}
if(! ~ $#debug 0) {
- echo $SERVER_NAME - $REQUEST_URI - >[1=2]
+ echo $SERVER_NAME^'/'^$REQUEST_URI - >[1=2]
}
if (! ~ $args '') {
@@ -176,22 +177,23 @@
inBlog = 'yes'
}
-# Redirections and other preprocessing
-if (~ $#redirectPermanent 1) {
- echo 'Status: 301 Moved Permanantly
-Location: '^$"redirectPermanent^'
+fn perm_redirect {
+ echo 'Status: 301 Moved Permanantly
+Location: '^$1^'
'
}
+
+# Redirections and other preprocessing
+if (~ $#redirectPermanent 1)
+ perm_redirect $"redirectPermanent
+
if not if (~ $#redirectPermanent 2) {
# Experimental regexp sub-based redirect, probably should find a nicer interface
# For now only used at sites/harmful.cat-v.org/software/OO_programming/_config
to=`{echo $REQUEST_URI|sed 's|'^$redirectPermanent(1)^'|'^$redirectPermanent(2)^'|'}
if(! ~ $to $REQUEST_URI)
- echo 'Status: 301 Moved Permanantly
-Location: '^$to^'
-
-'
+ perm_redirect $to
}
@@ -204,6 +206,8 @@
body=$sitedir/$body
rssuri=$uri
if (test -d $body) {
+ if(! ~ $body */)
+ perm_redirect $REQUEST_URI^'/'
body=$body/index
rssuri=$rssuri/
}