Automatically redirect directory requests to the correct canonical address
This commit is contained in:
parent
71d419f556
commit
cf09701ff9
1 changed files with 13 additions and 9 deletions
|
|
@ -125,6 +125,7 @@ fn genbody {
|
||||||
if not if(~ $#blogDirs 0) {
|
if not if(~ $#blogDirs 0) {
|
||||||
#echo 'Status: 404 Not Found\n\n' # should go before starting to print body
|
#echo 'Status: 404 Not Found\n\n' # should go before starting to print body
|
||||||
template.awk inc/404.tpl | rc $rcargs
|
template.awk inc/404.tpl | rc $rcargs
|
||||||
|
dprint 'NOT FOUND: '$SERVER_NAME^$REQUEST_URI^' - '^$"HTTP_REFERER
|
||||||
}
|
}
|
||||||
|
|
||||||
if(! ~ $#blogDirs 0) {
|
if(! ~ $#blogDirs 0) {
|
||||||
|
|
@ -150,7 +151,7 @@ fn dprint {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(! ~ $#debug 0) {
|
if(! ~ $#debug 0) {
|
||||||
echo $SERVER_NAME - $REQUEST_URI - >[1=2]
|
echo $SERVER_NAME^'/'^$REQUEST_URI - >[1=2]
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! ~ $args '') {
|
if (! ~ $args '') {
|
||||||
|
|
@ -176,22 +177,23 @@ for (i in ('' $args)) {
|
||||||
inBlog = 'yes'
|
inBlog = 'yes'
|
||||||
}
|
}
|
||||||
|
|
||||||
# Redirections and other preprocessing
|
fn perm_redirect {
|
||||||
if (~ $#redirectPermanent 1) {
|
echo 'Status: 301 Moved Permanantly
|
||||||
echo 'Status: 301 Moved Permanantly
|
Location: '^$1^'
|
||||||
Location: '^$"redirectPermanent^'
|
|
||||||
|
|
||||||
'
|
'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Redirections and other preprocessing
|
||||||
|
if (~ $#redirectPermanent 1)
|
||||||
|
perm_redirect $"redirectPermanent
|
||||||
|
|
||||||
if not if (~ $#redirectPermanent 2) {
|
if not if (~ $#redirectPermanent 2) {
|
||||||
# Experimental regexp sub-based redirect, probably should find a nicer interface
|
# 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
|
# For now only used at sites/harmful.cat-v.org/software/OO_programming/_config
|
||||||
to=`{echo $REQUEST_URI|sed 's|'^$redirectPermanent(1)^'|'^$redirectPermanent(2)^'|'}
|
to=`{echo $REQUEST_URI|sed 's|'^$redirectPermanent(1)^'|'^$redirectPermanent(2)^'|'}
|
||||||
if(! ~ $to $REQUEST_URI)
|
if(! ~ $to $REQUEST_URI)
|
||||||
echo 'Status: 301 Moved Permanantly
|
perm_redirect $to
|
||||||
Location: '^$to^'
|
|
||||||
|
|
||||||
'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -204,6 +206,8 @@ reqpath=$body
|
||||||
body=$sitedir/$body
|
body=$sitedir/$body
|
||||||
rssuri=$uri
|
rssuri=$uri
|
||||||
if (test -d $body) {
|
if (test -d $body) {
|
||||||
|
if(! ~ $body */)
|
||||||
|
perm_redirect $REQUEST_URI^'/'
|
||||||
body=$body/index
|
body=$body/index
|
||||||
rssuri=$rssuri/
|
rssuri=$rssuri/
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue