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

pgs.sh - relative links in subfolders with and without trailing / #115

Closed
josherrickson opened this issue Apr 1, 2024 · 5 comments · Fixed by #116
Closed

pgs.sh - relative links in subfolders with and without trailing / #115

josherrickson opened this issue Apr 1, 2024 · 5 comments · Fixed by #116

Comments

@josherrickson
Copy link

I've worked up a sample project at https://josherrickson-test.pgs.sh

The project consists of the following folder structure:

index.html
cat.png
folder/
├─ index.html
├─ dog.jpg

Both index.html link to both images using relative paths:

    <p>
      Cat: <img src="cat.png">
    </p>

    <p>
      Dog: <img src="dog.jpg">
    </p>

If I access https://josherrickson-test.pgs.sh, I properly see the cat image and the dog image is missing.

If I access https://josherrickson-test.pgs.sh/folder/index.html, I properly see the dog image and the cat is missing.

If I access https://josherrickson-test.pgs.sh/folder/, I properly see the dog image and the cat is missing

However, if I access https://josherrickson-test.pgs.sh/folder (note the missing trailing "/"), I DO see the cat image but do NOT see the dog image.

I'm uncertain if this is an issue on my end or pgs.sh's end. This issue also arises for CSS files (that's where I originally noticed it) but made this example with images to eliminate being some CSS weirdness.

@josherrickson
Copy link
Author

I should add, I've done some reading about how the presence/lack of trailing slash has a semantic meaning, but in previous hosts I've used, they've not been distinguishable.

@josherrickson
Copy link
Author

I tried adding this to _redirects but it didn't appear to work.

/folder        /folder/

Additionally, it would be quite a pain to have to manually add redirects for every folder if this were the solution. If this could be made to work in _redirects, does _redirects support regex?

@neurosnap
Copy link
Member

Hi! This is quite surprising behavior, but regardless of whether you add or remove the trailing slash to /folder, the page's content is identical, so this feels like what you mentioned: trailing slash is technically treated differently by the browser in regards to relative links.

I took at look at the default behavior for the python http.server using your site:

python3 -m http.server

The problem you described does not happen in it because when a user goes to: localhost:8000/folder it performs a 301 Moved Permanently to localhost:8000/folder/. It seems like even django enables this functionality by default: https://docs.djangoproject.com/en/1.10/ref/settings/#append-slash

Netlify also enabled this 301 redirect by default: https://docs.netlify.com/routing/redirects/redirect-options/#trailing-slash

The default behavior for pgs should not be surprising, so I have a feeling we are going to want to setup the 301 as well. Thoughts?

@neurosnap
Copy link
Member

I have a PR up, gonna test today/tomorrow and then deploy.

@josherrickson
Copy link
Author

Thanks - I agree that the 301 looks like the solution that most hosts land on. Appreciate the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants