fixed missing apache rewrite in root
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Sebastian Frank 2019-03-22 11:29:08 +01:00
parent 3573e23212
commit 4a9a3eec06
Signed by: apairon
GPG Key ID: 7270D06DDA7FE8C3
3 changed files with 31 additions and 12 deletions

View File

@ -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 {

View File

@ -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
<IfModule mod_headers.c>
RewriteEngine on
`
rewriteMacro := func(e, c, x, xx string) string {

View File

@ -10,7 +10,7 @@ func Run(inDir, outDir string, defaultPathConfig *PathConfig) {
ProcessAssets()
WriteWebserverConfig()
tree.WriteWebserverConfig()
Wait()
}