Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

404 redirects with hugo server fail in multilingual mode on Windows #10314

Closed
jmooring opened this issue Sep 22, 2022 · 5 comments · Fixed by #10316
Closed

404 redirects with hugo server fail in multilingual mode on Windows #10314

jmooring opened this issue Sep 22, 2022 · 5 comments · Fixed by #10316
Assignees
Milestone

Comments

@jmooring
Copy link
Member

structure
config/
├── _default/
│   └── config.toml
└── development/
    └── server.toml
content/
├── en/
│   └── _index.md
└── es/
    └── _index.md
layouts/
├── _default/
│   ├── baseof.html
│   ├── home.html
│   ├── list.html
│   └── single.html
└── 404.html
config\_default\config.toml
baseURL = 'https://example.org/'
title = 'Hugo Forum Topic #40568'

defaultContentLanguageInSubdir = true

[languages.en]
contentDir = 'content/en'
languageCode = 'en-US'
languageName = 'English'
weight = 1

[languages.es]
contentDir = 'content/es'
languageCode = 'es-ES'
languageName = 'Espanol'
weight = 2
config\development\server.toml
[[redirects]]
from = '/en/**'
to = '/en/404.html'
status = 404

[[redirects]]
from = '/es/**'
to = '/es/404.html'
status = 404

See:
https://github.com/gohugoio/hugo/blob/master/commands/server.go#L439

I suspect that this:

file, err := fs.Open(filepath.FromSlash(strings.TrimPrefix(redirect.To, u.Path)))

Should be this:

file, err := fs.Open(strings.TrimPrefix(redirect.To, u.Path))

MRE:

git clone --single-branch -b hugo-forum-topic-40568 https://github.com/jmooring/hugo-testing hugo-forum-topic-40568
cd hugo-forum-topic-40568
hugo server

Reference:
https://discourse.gohugo.io/t/404-pages-on-localhost-for-multilingual-site-failing/40568/15

@bep
Copy link
Member

bep commented Sep 22, 2022

file, err := fs.Open(filepath.FromSlash(strings.TrimPrefix(redirect.To, u.Path)))

I doubt that that is the culprit.

@bep bep removed the NeedsTriage label Sep 22, 2022
@bep bep added this to the v0.104.0 milestone Sep 22, 2022
@jmooring
Copy link
Member Author

I doubt that that is the culprit.

The err value is "http: invalid character in file path"

@bep
Copy link
Member

bep commented Sep 22, 2022

The err value is "http: invalid character in file path"

I will boot up my Windows VM and have a look tomorrow ... It's Windows 8 and every time i boot it I get a million update notifications.

bep added a commit that referenced this issue Sep 23, 2022
bep added a commit that referenced this issue Sep 23, 2022
bep added a commit to bep/hugo that referenced this issue Sep 23, 2022
@bep bep self-assigned this Sep 23, 2022
bep added a commit to bep/hugo that referenced this issue Sep 23, 2022
@bep
Copy link
Member

bep commented Sep 23, 2022

The err value is "http: invalid character in file path"

Yea, right, I misread what file system we're reading here, you were right about the "culprit" :-)

bep added a commit to bep/hugo that referenced this issue Sep 23, 2022
bep added a commit that referenced this issue Sep 23, 2022
bep added a commit to bep/hugo that referenced this issue Sep 23, 2022
Looking at the code as a whole, we ended up with a little to much "buttons". It turns out that doing case insensitive matching (lower both pattern and strings to match) performs just fine. Or at least, it
gives the penalty to the people who uses mixed case filenames.

```
GetGlob/Default_cache-10                          10.6ns ± 2%    10.6ns ± 1%   ~     (p=0.657 n=4+4)
GetGlob/Filenames_cache,_lowercase_searchs-10     10.6ns ± 2%    10.6ns ± 0%   ~     (p=1.000 n=4+4)
GetGlob/Filenames_cache,_mixed_case_searchs-10    29.7ns ± 1%    29.6ns ± 1%   ~     (p=0.886 n=4+4)
GetGlob/GetGlob-10                                13.7ns ± 1%    13.7ns ± 0%   ~     (p=0.429 n=4+4)

name                                            old alloc/op   new alloc/op   delta
GetGlob/Default_cache-10                           0.00B          0.00B        ~     (all equal)
GetGlob/Filenames_cache,_lowercase_searchs-10      0.00B          0.00B        ~     (all equal)
GetGlob/Filenames_cache,_mixed_case_searchs-10     5.00B ± 0%     5.00B ± 0%   ~     (all equal)
GetGlob/GetGlob-10                                 0.00B          0.00B        ~     (all equal)

name                                            old allocs/op  new allocs/op  delta
GetGlob/Default_cache-10                            0.00           0.00        ~     (all equal)
GetGlob/Filenames_cache,_lowercase_searchs-10       0.00           0.00        ~     (all equal)
GetGlob/Filenames_cache,_mixed_case_searchs-10      1.00 ± 0%      1.00 ± 0%   ~     (all equal)
GetGlob/GetGlob-10
```

Updates gohugoio#10314
bep added a commit to bep/hugo that referenced this issue Sep 23, 2022
Looking at the code as a whole, we ended up with a little to much "buttons". It turns out that doing case insensitive matching (lower both pattern and strings to match) performs just fine. Or at least, it
gives the penalty to the people who uses mixed case filenames.

```
GetGlob/Default_cache-10                          10.6ns ± 2%    10.6ns ± 1%   ~     (p=0.657 n=4+4)
GetGlob/Filenames_cache,_lowercase_searchs-10     10.6ns ± 2%    10.6ns ± 0%   ~     (p=1.000 n=4+4)
GetGlob/Filenames_cache,_mixed_case_searchs-10    29.7ns ± 1%    29.6ns ± 1%   ~     (p=0.886 n=4+4)
GetGlob/GetGlob-10                                13.7ns ± 1%    13.7ns ± 0%   ~     (p=0.429 n=4+4)

name                                            old alloc/op   new alloc/op   delta
GetGlob/Default_cache-10                           0.00B          0.00B        ~     (all equal)
GetGlob/Filenames_cache,_lowercase_searchs-10      0.00B          0.00B        ~     (all equal)
GetGlob/Filenames_cache,_mixed_case_searchs-10     5.00B ± 0%     5.00B ± 0%   ~     (all equal)
GetGlob/GetGlob-10                                 0.00B          0.00B        ~     (all equal)

name                                            old allocs/op  new allocs/op  delta
GetGlob/Default_cache-10                            0.00           0.00        ~     (all equal)
GetGlob/Filenames_cache,_lowercase_searchs-10       0.00           0.00        ~     (all equal)
GetGlob/Filenames_cache,_mixed_case_searchs-10      1.00 ± 0%      1.00 ± 0%   ~     (all equal)
GetGlob/GetGlob-10
```

Updates gohugoio#10314
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants