From 4a9a3eec06b5b7a937787dfca931a752b964b1eb Mon Sep 17 00:00:00 2001 From: Sebastian Frank Date: Fri, 22 Mar 2019 11:29:08 +0100 Subject: [PATCH] fixed missing apache rewrite in root --- pkg/mark2web/content.go | 19 +++++++++++-------- pkg/mark2web/htaccess.go | 22 +++++++++++++++++++--- pkg/mark2web/run.go | 2 +- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/pkg/mark2web/content.go b/pkg/mark2web/content.go index e5bfc39..01f5bce 100644 --- a/pkg/mark2web/content.go +++ b/pkg/mark2web/content.go @@ -76,15 +76,18 @@ func (node *TreeNode) ProcessContent() { curNavPath = "" } - goTo := node.Config.This.GoTo - if goTo != nil && *goTo != "" { - goToFixed := *goTo - if strings.HasPrefix(goToFixed, "/") { - goToFixed = helper.BackToRoot(curNavPath) + goToFixed - } - goToFixed = path.Clean(goToFixed) + if node.root != node { + // write htaccess for rewrites, root will be written in WriteWebserverConfig() + goTo := node.Config.This.GoTo + if goTo != nil && *goTo != "" { + goToFixed := *goTo + if strings.HasPrefix(goToFixed, "/") { + goToFixed = helper.BackToRoot(curNavPath) + goToFixed + } + goToFixed = path.Clean(goToFixed) - htaccessRedirect(node.OutputPath, goToFixed) + htaccessRedirect(node.OutputPath, goToFixed) + } } for _, file := range node.InputFiles { diff --git a/pkg/mark2web/htaccess.go b/pkg/mark2web/htaccess.go index 637c2eb..65e5e10 100644 --- a/pkg/mark2web/htaccess.go +++ b/pkg/mark2web/htaccess.go @@ -3,6 +3,7 @@ package mark2web import ( "io/ioutil" "regexp" + "strings" "gitbase.de/apairon/mark2web/pkg/helper" ) @@ -22,10 +23,27 @@ RewriteRule ^$ %{REQUEST_URI}`+goTo+`/ [R,L] } // WriteWebserverConfig build the config for pre compression and more -func WriteWebserverConfig() { +func (tree *TreeNode) WriteWebserverConfig() { + goTo := "" + if g := tree.Config.This.GoTo; g != nil && *g != "" { + goTo = strings.TrimPrefix(*g, "/") + } + switch Config.Webserver.Type { case "apache": configStr := ` +RewriteEngine on + +` + + if goTo != "" { + configStr += ` +RewriteRule ^$ %{REQUEST_URI}` + goTo + `/ [R,L] + +` + } + + configStr += ` AddCharset UTF-8 .html AddCharset UTF-8 .json AddCharset UTF-8 .js @@ -34,8 +52,6 @@ AddCharset UTF-8 .css RemoveLanguage .br - - RewriteEngine on ` rewriteMacro := func(e, c, x, xx string) string { diff --git a/pkg/mark2web/run.go b/pkg/mark2web/run.go index 3fda4d5..5c0b0f5 100644 --- a/pkg/mark2web/run.go +++ b/pkg/mark2web/run.go @@ -10,7 +10,7 @@ func Run(inDir, outDir string, defaultPathConfig *PathConfig) { ProcessAssets() - WriteWebserverConfig() + tree.WriteWebserverConfig() Wait() }