@@ -80,7 +80,7 @@ local function setup()
8080 baseUrl = "http://:host:/",
8181 languageCode = "en",
8282
83- ignoreFiles = {"%.tmp$"},
83+ ignoreFiles = {"%.lnk$","%. tmp$","^Thumbs%.db $"},
8484 ignoreFolders = {"^%."},
8585 }
8686 ]=], {
@@ -1651,7 +1651,7 @@ local function buildWebsite()
16511651
16521652 -- Validate targets.
16531653 for url, targetUrl in pairsSorted(allRedirections) do
1654- if targetUrl:find"^/" and not site._writtenOutputUrls[targetUrl] then
1654+ if targetUrl:find"^/" and not site._writtenOutputUrls[targetUrl:gsub("[?#].*", "") ] then
16551655 errorNoPos("Missing target page for redirection: %s -> %s", url, targetUrl)
16561656 end
16571657 end
@@ -1700,17 +1700,18 @@ local function buildWebsite()
17001700 if next(site._htaErrors) then
17011701 local b = newStringBuilder()
17021702
1703- for errCode, target in pairsSorted(site._htaErrors) do
1703+ for errCode, targetDoc in pairsSorted(site._htaErrors) do
17041704 -- The target may be a URL or HTML code.
1705- --
1706- -- @Incomplete: Does Apache rewrite URLs to error documents? I don't think v2.2 did, but maybe
1707- -- that has changed. If so, we should test for multiple file locations. :ApacheErrorDocumentFile
1708- --
1709- if target:find"^/%S*$" and not isFile(DIR_OUTPUT..target) then
1710- errorNoPos("Missing target page for error %d document (in output folder): %s%s", errCode, DIR_OUTPUT, target)
1705+ if targetDoc:find"^/%S*$" then
1706+ -- @Incomplete: Does Apache rewrite URLs to error documents? I don't think v2.2 did, but maybe
1707+ -- that has changed. If so, we should test for multiple file locations. :ApacheErrorDocumentFile
1708+ if not isFile(DIR_OUTPUT..targetDoc:gsub("[?#].*", "")) then
1709+ errorNoPos("%s: Missing target page for error %d document (in output folder): %s%s", maybeFullPath"config.lua", errCode, DIR_OUTPUT, targetDoc)
1710+ end
1711+ targetDoc = fixRelativeUrl(targetDoc)
17111712 end
17121713
1713- b("ErrorDocument %d %s\n", errCode, target )
1714+ b("ErrorDocument %d %s\n", errCode, targetDoc )
17141715 end
17151716
17161717 contents = F("%s\n%s", contents, b())
@@ -1751,24 +1752,33 @@ local function buildWebsite()
17511752 b("\t# Redirect moved resources.\n")
17521753
17531754 for url, targetUrl in pairsSorted(site._writtenRedirects) do
1755+ -- Make absolute target URLs relative if possible.
17541756 if targetUrl:sub(1, #site.baseUrl.v) == site.baseUrl.v then
17551757 targetUrl = targetUrl:sub(#site.baseUrl.v) -- Note: We keep the initial '/'.
17561758 end
17571759
1760+ url = fixRelativeUrl(url)
1761+ targetUrl = fixRelativeUrl(targetUrl)
1762+
17581763 b('\tRewriteCond %%{REQUEST_URI} "=%s"\n', url)
17591764 b('\tRewriteRule .* "%s" [R=301,L]\n', escapeRuleSub(targetUrl))
17601765 end
17611766
17621767 for url, targetUrl in pairsSorted(site._unwrittenRedirects) do
1768+ -- @Copypaste from above.
1769+
1770+ -- Make absolute target URLs relative if possible.
17631771 if targetUrl:sub(1, #site.baseUrl.v) == site.baseUrl.v then
17641772 targetUrl = targetUrl:sub(#site.baseUrl.v) -- Note: We keep the initial '/'.
17651773 end
17661774
17671775 local slug, query = url:match"^(.-)%?(.*)$"
17681776 if not slug then slug = url end
17691777
1770- b('\tRewriteCond %%{REQUEST_URI} "=%s"\n', slug)
1778+ slug = fixRelativeUrl(slug)
1779+ targetUrl = fixRelativeUrl(targetUrl)
17711780
1781+ b('\tRewriteCond %%{REQUEST_URI} "=%s"\n', slug)
17721782 if query then
17731783 b('\tRewriteCond %%{QUERY_STRING} "=%s"\n', query)
17741784 end
@@ -1796,6 +1806,7 @@ local function buildWebsite()
17961806 b("\tRewriteCond %{ENV:REDIRECT_STATUS} ^$\n")
17971807
17981808 for i, urlPrefix in ipairs(htaDenyAccess) do
1809+ urlPrefix = fixRelativeUrl(urlPrefix)
17991810 b(
18001811 '\tRewriteCond %%{REQUEST_URI} "^%s"%s\n',
18011812 escapeCondPat(urlPrefix),
@@ -1808,16 +1819,20 @@ local function buildWebsite()
18081819 end
18091820
18101821 if htaPrettyUrlDir ~= "" then
1822+ if not isDirectory(DIR_OUTPUT.."/"..htaPrettyUrlDir) then
1823+ errorNoPos("%s: config.htaccess.XXX_prettyUrlDirectory points to a missing directory (in output folder): %s/%s", maybeFullPath"config.lua", DIR_OUTPUT, htaPrettyUrlDir)
1824+ end
1825+
18111826 b('\t# Point to "%s" directory.\n', htaPrettyUrlDir)
18121827 b("\tRewriteCond %{REQUEST_FILENAME} !-f\n")
1813- b('\tRewriteCond "%%{DOCUMENT_ROOT}/%s /%%{REQUEST_URI}" -f\n', escapeTestStr(htaPrettyUrlDir))
1814- b('\tRewriteRule .* "/%s /$0" [L]\n', escapeRuleSub(htaPrettyUrlDir))
1828+ b('\tRewriteCond "%%{DOCUMENT_ROOT}%s%s /%%{REQUEST_URI}" -f\n', fixRelativeUrl"/" , escapeTestStr(htaPrettyUrlDir))
1829+ b('\tRewriteRule .* "%s%s /$0" [L]\n', fixRelativeUrl"/" , escapeRuleSub(htaPrettyUrlDir))
18151830 b("\n")
18161831
18171832 b("\tRewriteCond %{REQUEST_FILENAME} !-f\n")
18181833 b("\tRewriteCond %{REQUEST_URI} !^/$\n")
1819- b('\tRewriteCond "%%{DOCUMENT_ROOT}/%s /%%{REQUEST_URI}/" -d\n', escapeTestStr(htaPrettyUrlDir))
1820- b('\tRewriteRule .* "/%s /$0/" [L]\n', escapeRuleSub(htaPrettyUrlDir))
1834+ b('\tRewriteCond "%%{DOCUMENT_ROOT}%s%s /%%{REQUEST_URI}/" -d\n', fixRelativeUrl"/" , escapeTestStr(htaPrettyUrlDir))
1835+ b('\tRewriteRule .* "%s%s /$0/" [L]\n', fixRelativeUrl"/" , escapeRuleSub(htaPrettyUrlDir))
18211836 b("\n")
18221837 end
18231838
@@ -1830,8 +1845,9 @@ local function buildWebsite()
18301845
18311846 local directives = b()
18321847
1833- local count1 ; contents, count1 = gsubPlainSub(contents, "#[ \t]*:webgen%.rewriting:[ \t]*\n", directives)
1834- local count2 ; contents, count2 = gsubPlainSub(contents, "#[ \t]*:webgen%.rewriting:[ \t]*$", directives)
1848+ local count1, count2
1849+ contents, count1 = gsubPlainSub(contents, "#[ \t]*:webgen%.rewriting:[ \t]*\n", directives)
1850+ contents, count2 = gsubPlainSub(contents, "#[ \t]*:webgen%.rewriting:[ \t]*$", directives)
18351851 if count1+count2 == 0 then
18361852 contents = F("%s\n%s", contents, directives)
18371853 end
0 commit comments