Relative path in Create a Website style projects result in unexpected behavior with relative urls

In a Create a Website style project I have the following four files:

/test/index.html
/test/script.js
/index.html
/script.js

Each index.html has a script tag like follows (note relative url and not absolute):

<script src="script.js"></script>

If I visit “myproject.glitch.me/test” (note no trailing slash),
then script script tag in /test/index.html does not resolve to /test/script.js but it instead resolves to /script.js.

If I visit “myproject.glitch.me/test/” (note inclusion of trailing slash), then the script tag resolves to /test/script.js as expected.

I think it would be a better experience for Create a Website style projects if visiting what resolves to a subdirectory without a trailing slash redirected to the trailing slash url to assist with relative paths.

Looks like performing the redirect is also recommended by the Google Webmasters blog and seems reasonable: https://webmasters.googleblog.com/2010/04/to-slash-or-not-to-slash.html

so this issue is caused because the behavior in glitch is the same as the behavior on your local file system, or a standard http server: https://stackoverflow.com/questions/10867052/cannot-serve-static-files-with-express-routing-and-no-trailing-slash . I’m not sure why web standards don’t just work with trailing slashes, ugh internet.

as suggested in the stack overflow answer, one thing you can do is to create a full node app and use express routing to create that redirect.

Oh for sure. I just like the simplicity of the Create a Website feature and want to get some edge cases hammered out :slight_smile:

2 Likes